Integrated: 8335817: javac AssertionError addLocalVar checkNull

Jan Lahoda jlahoda at openjdk.org
Mon Jul 15 11:28:57 UTC 2024


On Wed, 10 Jul 2024 12:16:58 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> 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.

This pull request has now been integrated.

Changeset: 2b0adfc2
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/2b0adfc2decf47f6f49f072549c96f301f275285
Stats:     157 lines in 2 files changed: 155 ins; 0 del; 2 mod

8335817: javac AssertionError addLocalVar checkNull

Reviewed-by: vromero, mcimadamore

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

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


More information about the compiler-dev mailing list