-
Bug
-
Resolution: Fixed
-
P3
-
21
-
b14
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8315671 | 21.0.1 | Jan Lahoda | P3 | Resolved | Fixed | b10 |
public class Foo {
public static void main(final String[] args) throws Exception {
final String _ = "foo bar";
System.out.println("Demo done");
}
}
This uses a unnamed variable.
Now compile it using:
javac -g --enable-preview -source 21 Foo.java
Notice the -g option. The compilation goes through fine. Now try to run that class:
java --enable-preview Foo
This fails with the following error
Error: LinkageError occurred while loading main class Foo
java.lang.ClassFormatError: Illegal field name "" in class Foo
Everything, including running the compiled class, works fine if -g is left out during compilation.
javac version in use:
javac -version
javac 21-ea
java version in use:
java -version
openjdk version "21-ea" 2023-09-19
OpenJDK Runtime Environment (build 21-ea+33-2490)
OpenJDK 64-Bit Server VM (build 21-ea+33-2490, mixed mode, sharing)
- backported by
-
JDK-8315671 javac -g on a java file which uses unnamed variable leads to ClassFormatError when launching that class
- Resolved
- duplicates
-
JDK-8321058 Unnamed variable in functional interface doesn't work
- Closed
-
JDK-8317002 Combination of javac flags produce broken bytecode in compiler output
- Closed
-
JDK-8317378 Using _ in try with resources results in ClassFormatError
- Closed
- links to
-
Commit openjdk/jdk21u/49bef915
-
Commit openjdk/jdk/adfc1d6c
-
Review openjdk/jdk21u/128
-
Review openjdk/jdk/15083