-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
17
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
openjdk version "17.0.14" 2025-01-21 LTS
OpenJDK Runtime Environment Zulu17.56+15-CA (build 17.0.14+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.56+15-CA (build 17.0.14+7-LTS, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
ACC_MANDATED is a valid flag in MethodParameters for Java 17, and some compilers (like jdk21 with --release option) will emit it. However, when this flag is present, it prevents Constructor.getParameters() from returning generic information for a record constructor's parameters. This is a runtime bug because java.lang.reflect should yield proper generic information, consistently.
If the fix forJDK-8320575 were to be backported to JDK 17, it would SOLVE this issue. The problem is that JDK-8320575 only solved the issue for JDK 21 and beyond, even though JDK 17 is affected by this challenge as well. This matters because new versions of javac (like jdk21) add the mandated flag even if --release 17 is set, which means that compiling jdk21 with --release 17 option will break programs that use generic type information on a Java 17 VM.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Get a Java 17-compatible class file which uses ACC_MANDATED for the constructor parameters of a record class. Try to reflect on this class at runtime. Try to access generic information for the constructor parameters, and you'll see that they are erased.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Generic information is accessible. Parameter.getAnnotatedType() returns an instance of AnnotatedParameterizedType when the parameter is generically qualified.
ACTUAL -
Generic information is not always accessible. When the parameter has the mandated flag set, Parameter.getAnnotatedType() does not return an instance of AnnotatedParameterized Type, even though the parameter is genericallly qualified.
---------- BEGIN SOURCE ----------
On OpenJDK 21 (21.0.6+7-LTS), behavior is correct and the bug doesn't exist. Hence, the reproducer MUST be run with OpenJDK 17.
---------- END SOURCE ----------
openjdk version "17.0.14" 2025-01-21 LTS
OpenJDK Runtime Environment Zulu17.56+15-CA (build 17.0.14+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.56+15-CA (build 17.0.14+7-LTS, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
ACC_MANDATED is a valid flag in MethodParameters for Java 17, and some compilers (like jdk21 with --release option) will emit it. However, when this flag is present, it prevents Constructor.getParameters() from returning generic information for a record constructor's parameters. This is a runtime bug because java.lang.reflect should yield proper generic information, consistently.
If the fix for
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Get a Java 17-compatible class file which uses ACC_MANDATED for the constructor parameters of a record class. Try to reflect on this class at runtime. Try to access generic information for the constructor parameters, and you'll see that they are erased.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Generic information is accessible. Parameter.getAnnotatedType() returns an instance of AnnotatedParameterizedType when the parameter is generically qualified.
ACTUAL -
Generic information is not always accessible. When the parameter has the mandated flag set, Parameter.getAnnotatedType() does not return an instance of AnnotatedParameterized Type, even though the parameter is genericallly qualified.
---------- BEGIN SOURCE ----------
On OpenJDK 21 (21.0.6+7-LTS), behavior is correct and the bug doesn't exist. Hence, the reproducer MUST be run with OpenJDK 17.
---------- END SOURCE ----------
- relates to
-
JDK-8320575 generic type information lost on mandated parameters of record's compact constructors
-
- Closed
-