RFR: 8304883: Record Deconstruction causes bytecode error [v2]
Jan Lahoda
jlahoda at openjdk.org
Tue Mar 28 09:30:39 UTC 2023
> 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.
Jan Lahoda has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains two commits:
- Merge branch 'master' into JDK-8304883
- 8304883: Record Deconstruction causes bytecode error
-------------
Changes: https://git.openjdk.org/jdk/pull/13192/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13192&range=01
Stats: 67 lines in 2 files changed: 45 ins; 13 del; 9 mod
Patch: https://git.openjdk.org/jdk/pull/13192.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/13192/head:pull/13192
PR: https://git.openjdk.org/jdk/pull/13192
More information about the compiler-dev
mailing list