RFR: 8327683: Crash with primitive type pattern and generic expression in instanceof
Aggelos Biboudis
abimpoudis at openjdk.org
Fri Mar 8 11:19:17 UTC 2024
When compiling the following code, javac results in `java.lang.AssertionError: T.intValue`:
public static <T extends Integer> boolean wideningReferenceConversionUnboxing(T i) {
return i instanceof int ii;
}
The translated code after `Lower`, results in a generated assignment `(int)i.intValue()`. The reason for this bug is that the variable `i` required to have the erased type, set. This PR addresses this issue in `TransPatterns`:
public static boolean wideningReferenceConversionUnboxing(Integer i) {
return (let int ii in
(let /*synthetic*/ final T tmp4500$ = i in tmp4500$ != null && (let /*synthetic*/ final T tmp4500$ = i in tmp4500$ != null)) &&
(let ii = (int)i.intValue(); in true));
}
We also observe a duplicated check in the generated code: `(let /*synthetic*/ final T tmp4500$ = i in tmp4500$ != null`. This PR also tidies up the relevant code transformation in `Lower`.
-------------
Commit messages:
- 8327683: Crash with primitive type pattern and generic expression in instanceof
Changes: https://git.openjdk.org/jdk/pull/18168/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18168&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8327683
Stats: 241 lines in 5 files changed: 204 ins; 15 del; 22 mod
Patch: https://git.openjdk.org/jdk/pull/18168.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/18168/head:pull/18168
PR: https://git.openjdk.org/jdk/pull/18168
More information about the compiler-dev
mailing list