RFR: 8304883: Record Deconstruction causes bytecode error
Jan Lahoda
jlahoda at openjdk.org
Mon Mar 27 13:55:41 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.
-------------
Commit messages:
- 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=00
Issue: https://bugs.openjdk.org/browse/JDK-8304883
Stats: 62 lines in 2 files changed: 46 ins; 13 del; 3 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