-
Bug
-
Resolution: Fixed
-
P3
-
21, 22, 23
-
b25
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8334608 | 21.0.6-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8343828 | 21.0.6 | Goetz Lindenmaier | P3 | Resolved | Fixed | b03 |
Tested on MacBook Pro M2, Ventura 13.4
Java 21.0.1
A DESCRIPTION OF THE PROBLEM :
When, via reflection, trying to determine the generic type of an argument of the default record constructor,
the generic type cannot be determined in Java 21.
This did work in pre 21 versions. Tested in 17.0.9.
REGRESSION : Last worked in version 17.0.9
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run provided test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect generic type to be available in the default record constructor.
ACTUAL -
No generic type information available.
---------- BEGIN SOURCE ----------
import java.util.Optional;
public class Reproducer {
interface NoConstructorDeclarations {
record Person(Optional<String> name, Optional<Integer> age) {}
}
interface AnnotatedCompactConstructor {
record Person(Optional<String> name, Optional<Integer> age) {
@Deprecated public Person {}
}
}
interface AnotatedExplicitCanonicalConstructor {
record Person(Optional<String> name, Optional<Integer> age) {
@Deprecated
public Person(Optional<String> name, Optional<Integer> age) {
this.name = name;
this.age = age;
}
}
}
public static void main(String args[]) {
for(var approach: Reproducer.class.getDeclaredClasses()) {
Class<?> recordClass = approach.getClasses()[0];
System.out.println(approach.getSimpleName());
var constructor = recordClass.getConstructors()[0];
System.out.println(constructor.isAnnotationPresent(Deprecated.class));
for(var p: constructor.getParameters()) {
System.out.println(p);
}
System.out.println();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Explicitly add a canonical constructor with all record properties.
FREQUENCY : always
- backported by
-
JDK-8334608 generic type information lost on mandated parameters of record's compact constructors
- Resolved
-
JDK-8343828 generic type information lost on mandated parameters of record's compact constructors
- Resolved
- csr for
-
JDK-8321819 generic type information lost on mandated parameters of record's compact constructors
- Closed
- duplicates
-
JDK-8331026 Compact record constructor is missing generic type info on parameters
- Closed
- relates to
-
JDK-8292275 javac does not emit SYNTHETIC and MANDATED flags for parameters by default
- Resolved
- links to
-
Commit openjdk/jdk/7bf1989f
-
Commit(master) openjdk/jdk21u-dev/582a2bef
-
Review openjdk/jdk/17070
-
Review(master) openjdk/jdk21u-dev/1026