Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8268834 | 18 | Robo Duke | P3 | Resolved | Fixed | b02 |
A DESCRIPTION OF THE PROBLEM :
JLS 14.21 for Java 16 states that
YieldStatement:
yield Expression ;
but the relevant code parsing this expression does not allow expressions starting with ~ or !:
https://github.com/openjdk/jdk/blob/5cee23a9ed0b7fe2657be7492d9c1f78fcd02ebf/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#L2662-L2665
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached source code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program compiles successfully
ACTUAL -
> javac Yield.java
Yield.java:5: error: not a statement
yield !1;
^
Yield.java:5: error: ';' expected
yield !1;
^
2 errors
---------- BEGIN SOURCE ----------
class Yield {
public static void main(String... args) {
int value = switch (1) {
default -> {
yield !1;
}
};
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap the expression in ()
FREQUENCY : always
JLS 14.21 for Java 16 states that
YieldStatement:
yield Expression ;
but the relevant code parsing this expression does not allow expressions starting with ~ or !:
https://github.com/openjdk/jdk/blob/5cee23a9ed0b7fe2657be7492d9c1f78fcd02ebf/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#L2662-L2665
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached source code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program compiles successfully
ACTUAL -
> javac Yield.java
Yield.java:5: error: not a statement
yield !1;
^
Yield.java:5: error: ';' expected
yield !1;
^
2 errors
---------- BEGIN SOURCE ----------
class Yield {
public static void main(String... args) {
int value = switch (1) {
default -> {
yield !1;
}
};
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap the expression in ()
FREQUENCY : always
- backported by
-
JDK-8268834 yield statements doesn't allow ~ or ! unary operators in expression
-
- Resolved
-