-
Bug
-
Resolution: Unresolved
-
P4
-
17.0.2, 17.0.6, 20, 21
-
$ uname -a Linux yrodiere.redhat 6.1.7-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jan 18 17:11:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Tested with multiple Java versions, including 17, 20 and 21:
$ java -version openjdk version "17.0.6" 2023-01-17 OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10) OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)
$ java -version openjdk version "20" 2023-03-21 OpenJDK Runtime Environment (build 20+36-2344) OpenJDK 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)
$ java -version openjdk version "21-ea" 2023-09-19 OpenJDK Runtime Environment (build 21-ea+10-784) OpenJDK 64-Bit Server VM (build 21-ea+10-784, mixed mode, sharing)
$ uname -a Linux yrodiere.redhat 6.1.7-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jan 18 17:11:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Tested with multiple Java versions, including 17, 20 and 21: $ java -version openjdk version "17.0.6" 2023-01-17 OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10) OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing) $ java -version openjdk version "20" 2023-03-21 OpenJDK Runtime Environment (build 20+36-2344) OpenJDK 64-Bit Server VM (build 20+36-2344, mixed mode, sharing) $ java -version openjdk version "21-ea" 2023-09-19 OpenJDK Runtime Environment (build 21-ea+10-784) OpenJDK 64-Bit Server VM (build 21-ea+10-784, mixed mode, sharing)
-
x86_64
-
linux
Affects OpenJDK 17.0.6, 20+36-2344 (GA), 21-ea+10-784.
With the following classes:
public class TopLevel {
public Class<?> myInstanceMethod() {
class InstanceMethodNamedClass {
public InstanceMethodNamedClass(@MyParameterAnnotation String foo) {
}
}
return InstanceMethodNamedClass.class;
}
}
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface MyParameterAnnotation {
}
... calling `getParameterAnnotations()`on the constructor of `InstanceMethodNamedClass` will return an array that excludes the implicit enclosing parameter representing the instance of `TopLevel`:
var clazz = new TopLevel().myInstanceMethod();
var constructor = clazz.getDeclaredConstructors()[0];
assert constructor.getParameters().length == 2; // succeeds
assert constructor.getParameterAnnotations().length == 2; // fails; length is actually 1
This behavior seems wrong since the javadoc of getParameterAnnotations() states:
> Synthetic and mandated parameters (see explanation below), such as the outer "this" parameter to an
> inner class constructor will be represented in the returned array
-----
Executable reproducer: see https://github.com/yrodiere/jdk-playground/tree/parameter-annotations, check out branch "parameter-annotations" and run `./mvnw clean install`
-----
Relates to JDK-8180892.
This bug is similar toJDK-8074977, but different since it is still present after JDK-8074977 was fixed.
With the following classes:
public class TopLevel {
public Class<?> myInstanceMethod() {
class InstanceMethodNamedClass {
public InstanceMethodNamedClass(@MyParameterAnnotation String foo) {
}
}
return InstanceMethodNamedClass.class;
}
}
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface MyParameterAnnotation {
}
... calling `getParameterAnnotations()`on the constructor of `InstanceMethodNamedClass` will return an array that excludes the implicit enclosing parameter representing the instance of `TopLevel`:
var clazz = new TopLevel().myInstanceMethod();
var constructor = clazz.getDeclaredConstructors()[0];
assert constructor.getParameters().length == 2; // succeeds
assert constructor.getParameterAnnotations().length == 2; // fails; length is actually 1
This behavior seems wrong since the javadoc of getParameterAnnotations() states:
> Synthetic and mandated parameters (see explanation below), such as the outer "this" parameter to an
> inner class constructor will be represented in the returned array
-----
Executable reproducer: see https://github.com/yrodiere/jdk-playground/tree/parameter-annotations, check out branch "parameter-annotations" and run `./mvnw clean install`
-----
Relates to JDK-8180892.
This bug is similar to
- relates to
-
JDK-5087240 (reflect) Constructor.getGenericParameterTypes for nested class w/ generics fail
-
- Closed
-
-
JDK-8180892 Correct handling of annotations on parameters
-
- Open
-
-
JDK-8334871 javac does not accept classfiles with certain permitted RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations attributes
-
- Closed
-