Integrated: 8328536: javac - crash on unknown type referenced in yield statement
Hannes Greule
hgreule at openjdk.org
Wed Jun 26 23:20:16 UTC 2024
On Tue, 19 Mar 2024 17:49:32 GMT, Hannes Greule <hgreule at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: 3796fdfc
Author: Hannes Greule <hgreule at openjdk.org>
Committer: Chen Liang <liach at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/3796fdfcedc2b2202b72cca062218f840960414c
Stats: 54 lines in 6 files changed: 47 ins; 3 del; 4 mod
8328536: javac - crash on unknown type referenced in yield statement
Co-authored-by: Jan Lahoda <jlahoda at openjdk.org>
Reviewed-by: jlahoda
-------------
PR: https://git.openjdk.org/jdk/pull/18383
More information about the compiler-dev
mailing list