Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7156633

(javac) incorrect errors when parsing variable declaration in block statements.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 8
    • tools
    • None
    • b36
    • generic
    • generic
    • Verified

      The errors generated by the parser for variables declared in a block statement
      are incorrect. Consider the following code:

      cat Foo.java
      public class Foo {
        void m1() {
          if (true)
            int x = 0;
        }
      }

      javac Foo.java
      Foo.java:4: error: '.class' expected
            int x = 0;
                ^
      Foo.java:4: error: not a statement
            int x = 0;
            ^
      Foo.java:4: error: illegal start of expression
            int x = 0;
                  ^
      Foo.java:4: error: ';' expected
            int x = 0;
                   ^
      4 errors

      javac generates 4 errors and none of them are accurate.

            ksrini Kumar Srinivasan
            ksrini Kumar Srinivasan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: