RFR: 8328536: javac - crash on unknown type referenced in yield statement

Hannes Greule hgreule at openjdk.org
Tue Mar 19 18:48:26 UTC 2024


Pasting  e.g.

I m(I i, int x) {
   return switch (x) {
        default -> i;
   };
}

in jshell will cause a crash if `I` is not declared already. This comes down to javac not creating an error type for the value of the (implicit) yield from the switch.

Javac will not crash but swallow the exception, and create a file containing the command line options.

I first thought about just checking for null of the type here https://github.com/openjdk/jdk/blob/9ca4ae3d3b746f1d75036d189ff98f02b73b948f/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L1640 but after a closer look, the `checkIdInternal` method seems a better fit, as it also updates the type normally.

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

Commit messages:
 - Fix jshell crash on unknown type in switch yield

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

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


More information about the compiler-dev mailing list