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

Hannes Greule hgreule at openjdk.org
Mon May 20 14:56:25 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.

Hannes Greule has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:

 - add testcase
 - Don't bail out early on erroneous type, adjust tests
 - Merge branch 'master' into fix/switch-yield-unknown-type-crash
 - Merge branch 'master' into fix/switch-yield-unknown-type-crash
 - Merge branch 'refs/heads/master' into fix/switch-yield-unknown-type-crash
 - add bug id
 - Fix jshell crash on unknown type in switch yield

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/18383/files
  - new: https://git.openjdk.org/jdk/pull/18383/files/846ac70c..e3f63b31

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=18383&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=18383&range=01-02

  Stats: 186428 lines in 3835 files changed: 102926 ins; 63002 del; 20500 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