Integrated: 8304883: Record Deconstruction causes bytecode error
Jan Lahoda
jlahoda at openjdk.org
Wed Apr 5 10:32:23 UTC 2023
On Mon, 27 Mar 2023 13:46:16 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Originally, we used to support cases like:
> `case null, String s when s.isEmpty() -> <expression>`
> where `s` could be `null` inside the expression, but the guard was only evaluated when `s != null`. This was implemented by augmenting the guard with `s == null || <original-guard>`.
>
> This feature has been dropped since then.
>
> Also note that in other cases, like:
>
> record R(Object o) {}
> Object o = new R(null);
> switch (o) {
> case R(var v) when v.toString().isEmpty() -> {}
> }
>
>
> We always expected a NPE on dereferencing the binding with value `null` (`v` in this case) in guard.
>
> But, the code to implement the `case null, <binding>` remained in javac, and is causing problems, because, while the user cannot write `case null, <binding>` anymore, internally the desugaring sometimes generates that (when factoring out common prefixes). And the original code will still augment the guards to `<binding> == null || <guard>`, which causes the variables that are assigned in the guard to not being definitely assigned after the augmented guard.
>
> The proposal is to simply remove the code that adds `<binding> == null || <guard>`, as there's no case where we would skip guards for `null` bindings anymore.
This pull request has now been integrated.
Changeset: 2aec910e
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/2aec910ea4bcd3a253a76a70323f9bebb49d8e91
Stats: 67 lines in 2 files changed: 45 ins; 13 del; 9 mod
8304883: Record Deconstruction causes bytecode error
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/13192
More information about the compiler-dev
mailing list