[jdk23] RFR: 8335817: javac AssertionError addLocalVar checkNull

Jan Lahoda jlahoda at openjdk.org
Mon Jul 15 15:07:21 UTC 2024


Hi all,

This pull request contains a backport of commit [2b0adfc2](https://github.com/openjdk/jdk/commit/2b0adfc2decf47f6f49f072549c96f301f275285) from the [openjdk/jdk](https://git.openjdk.org/jdk) repository.

The commit being backported was authored by Jan Lahoda on 15 Jul 2024 and was reviewed by Vicente Romero and Maurizio Cimadamore.

Thanks!

Original description:
Consider pattern matching with deconstruction patter, like:

boolean b = o instanceof R(String s);


This will get desugared into code similar to `o instanceof R r && r.component() instanceof String s`, except that the call to `component()` is guarded with a try-catch, wrapping any exception with a `MatchException`. The internal javac implementation is to create a synthetic catch clause, and attach it to the relevant enclosing block.

Now, consider an expression lambda with a deconstruction pattern matching, like `o -> o instanceof R(String s)`. There is no block in the lambda to which the catch could be attached. So, `TransPatterns` will expand the expression lambda to a block lambda, and inject the synthetic catches. But, `TransPatterns` will always do `return <expression-body>;`, even if the type of `<expression-body>` is void. This then leads to a crash during Gen, as a variable of type `void` is created.

The patch proposed here avoid creating `return <expression-body>;` for void-type expression.

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

Commit messages:
 - Backport 2b0adfc2decf47f6f49f072549c96f301f275285

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

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


More information about the compiler-dev mailing list