-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
P4
-
None
-
Affects Version/s: 21, 25
-
Component/s: tools
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Property settings:
file.encoding = UTF-8
file.separator = /
java.class.path =
java.class.version = 65.0
java.home = /root/hotspot-21/build/linux-x86_64-server-release/jdk
java.io.tmpdir = /tmp
java.library.path = /usr/java/packages/lib
/usr/lib64
/lib64
/lib
/usr/lib
java.runtime.name = OpenJDK Runtime Environment
java.runtime.version = 21.0.10-internal-adhoc.root.hotspot-21
java.specification.name = Java Platform API Specification
java.specification.vendor = Oracle Corporation
java.specification.version = 21
java.vendor = N/A
java.vendor.url = https://openjdk.org/
java.vendor.url.bug = https://bugreport.java.com/bugreport/
java.version = 21.0.10-internal
java.version.date = 2026-01-20
java.vm.compressedOopsMode = Zero based
java.vm.info = mixed mode
java.vm.name = OpenJDK 64-Bit Server VM
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.vendor = Oracle Corporation
java.vm.specification.version = 21
java.vm.vendor = Oracle Corporation
java.vm.version = 21.0.10-internal-adhoc.root.hotspot-21
jdk.debug = release
line.separator = \n
native.encoding = ANSI_X3.4-1968
os.arch = amd64
os.name = Linux
os.version = 5.15.0-60-generic
path.separator = :
stderr.encoding = ANSI_X3.4-1968
stdout.encoding = ANSI_X3.4-1968
sun.arch.data.model = 64
sun.boot.library.path = /root/hotspot-21/build/linux-x86_64-server-release/jdk/lib
sun.cpu.endian = little
sun.io.unicode.encoding = UnicodeLittle
sun.java.launcher = SUN_STANDARD
sun.jnu.encoding = ANSI_X3.4-1968
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
user.country = US
user.home = /root
user.language = en
user.name = root
openjdk version "21.0.10-internal" 2026-01-20
OpenJDK Runtime Environment (build 21.0.10-internal-adhoc.root.hotspot-21)
OpenJDK 64-Bit Server VM (build 21.0.10-internal-adhoc.root.hotspot-21, mixed mode)
A DESCRIPTION OF THE PROBLEM :
When compiling code that uses record pattern matching in an `instanceof` expression where the pattern type is a generic type parameter that shadows a record class with the same name, the compiler crashes with a `ClassCastException`.
In the generic method `test`, the type parameter `T` shadows the outer record class `T`. When the compiler tries to resolve `T` in the pattern `T(var ta, var tb, var tc)`, it may incorrectly assume it's dealing with a `ClassSymbol` (for a record) but instead finds a `TypeVariableSymbol`, leading to the cast exception.
---------- BEGIN SOURCE ----------
```
public class Test {
public record T(int a, int b, int c) {}
public <T> void test(Object obj) {
System.out.println(obj instanceof T(var ta, var tb, var tc));
}
public static void main(String[] args) {
Object value = new T(1, 2, 3);
new Test().<T>test(value);
}
}
```
---------- END SOURCE ----------
FREQUENCY :
ALWAYS
Property settings:
file.encoding = UTF-8
file.separator = /
java.class.path =
java.class.version = 65.0
java.home = /root/hotspot-21/build/linux-x86_64-server-release/jdk
java.io.tmpdir = /tmp
java.library.path = /usr/java/packages/lib
/usr/lib64
/lib64
/lib
/usr/lib
java.runtime.name = OpenJDK Runtime Environment
java.runtime.version = 21.0.10-internal-adhoc.root.hotspot-21
java.specification.name = Java Platform API Specification
java.specification.vendor = Oracle Corporation
java.specification.version = 21
java.vendor = N/A
java.vendor.url = https://openjdk.org/
java.vendor.url.bug = https://bugreport.java.com/bugreport/
java.version = 21.0.10-internal
java.version.date = 2026-01-20
java.vm.compressedOopsMode = Zero based
java.vm.info = mixed mode
java.vm.name = OpenJDK 64-Bit Server VM
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.vendor = Oracle Corporation
java.vm.specification.version = 21
java.vm.vendor = Oracle Corporation
java.vm.version = 21.0.10-internal-adhoc.root.hotspot-21
jdk.debug = release
line.separator = \n
native.encoding = ANSI_X3.4-1968
os.arch = amd64
os.name = Linux
os.version = 5.15.0-60-generic
path.separator = :
stderr.encoding = ANSI_X3.4-1968
stdout.encoding = ANSI_X3.4-1968
sun.arch.data.model = 64
sun.boot.library.path = /root/hotspot-21/build/linux-x86_64-server-release/jdk/lib
sun.cpu.endian = little
sun.io.unicode.encoding = UnicodeLittle
sun.java.launcher = SUN_STANDARD
sun.jnu.encoding = ANSI_X3.4-1968
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
user.country = US
user.home = /root
user.language = en
user.name = root
openjdk version "21.0.10-internal" 2026-01-20
OpenJDK Runtime Environment (build 21.0.10-internal-adhoc.root.hotspot-21)
OpenJDK 64-Bit Server VM (build 21.0.10-internal-adhoc.root.hotspot-21, mixed mode)
A DESCRIPTION OF THE PROBLEM :
When compiling code that uses record pattern matching in an `instanceof` expression where the pattern type is a generic type parameter that shadows a record class with the same name, the compiler crashes with a `ClassCastException`.
In the generic method `test`, the type parameter `T` shadows the outer record class `T`. When the compiler tries to resolve `T` in the pattern `T(var ta, var tb, var tc)`, it may incorrectly assume it's dealing with a `ClassSymbol` (for a record) but instead finds a `TypeVariableSymbol`, leading to the cast exception.
---------- BEGIN SOURCE ----------
```
public class Test {
public record T(int a, int b, int c) {}
public <T> void test(Object obj) {
System.out.println(obj instanceof T(var ta, var tb, var tc));
}
public static void main(String[] args) {
Object value = new T(1, 2, 3);
new Test().<T>test(value);
}
}
```
---------- END SOURCE ----------
FREQUENCY :
ALWAYS