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.
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.
- duplicates
-
JDK-5072282 Spurious extra error message when parsing simple if statement
-
- Closed
-