RFR: 8335817: javac AssertionError addLocalVar checkNull

Jan Lahoda jlahoda at openjdk.org
Wed Jul 10 20:09:29 UTC 2024


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:
 - 8335817: javac AssertionError addLocalVar checkNull

Changes: https://git.openjdk.org/jdk/pull/20110/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20110&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/20110.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/20110/head:pull/20110

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


More information about the compiler-dev mailing list