RFR: 8313323: javac -g on a java file which uses unnamed variable leads to ClassFormatError when launching that class

Jan Lahoda jlahoda at openjdk.org
Mon Jul 31 06:59:19 UTC 2023


When unnamed (`_`) variables are present, and javac emits the `LocalVariableTable` (and potentially the `LocalVariableTypeTable`), it includes the unnamed variable in the table. As the variable does not have a name, the table contains an empty name, which is not allowed by the spec, see [1], [2], [3].

The proposed solution is to simply not include the unnamed variables in these tables, but not adding them to the internal `Code.varBuffer`.

[1] https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.2.2
[2] https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.7.13
[3] https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.7.14

-------------

Commit messages:
 - Adding testcase for LocalVariableTypeTable.
 - 8313323: javac -g on a java file which uses unnamed variable leads to ClassFormatError when launching that class

Changes: https://git.openjdk.org/jdk/pull/15083/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15083&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8313323
  Stats: 51 lines in 2 files changed: 51 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/15083.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15083/head:pull/15083

PR: https://git.openjdk.org/jdk/pull/15083


More information about the compiler-dev mailing list