Support searches for non-public repeatable annotations
Prior to this commit, searches for non-public repeatable annotations failed with error messages similar to the following, since the repeatable annotation's container's `value()` method could not be invoked via reflection. JDK 8: java.lang.IllegalAccessError: tried to access class org.springframework.core.annotation.NestedRepeatableAnnotationsTests$A from class com.sun.proxy.$Proxy12 JDK 17: java.lang.IllegalAccessError: failed to access class org.springframework.core.annotation.NestedRepeatableAnnotationsTests$A from class jdk.proxy2.$Proxy12 (org.springframework.core.annotation.NestedRepeatableAnnotationsTests$A is in unnamed module of loader 'app'; jdk.proxy2.$Proxy12 is in module jdk.proxy2 of loader 'app') This commit makes it possible to search for non-public repeatable annotations by first attempting to invoke the repeatable annotation's container's `value()` method via the container's InvocationHandler (if the container is a JDK dynamic proxy) and then falling back to reflection for the method invocation if an error occurs (such as a SecurityException). Closes gh-29301
This commit is contained in:
@@ -181,7 +181,7 @@ class NestedRepeatableAnnotationsTests {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
|
||||
@Repeatable(A.Container.class)
|
||||
public @interface A {
|
||||
@interface A {
|
||||
|
||||
int value() default 0;
|
||||
|
||||
@@ -197,7 +197,7 @@ class NestedRepeatableAnnotationsTests {
|
||||
@Repeatable(B.Container.class)
|
||||
@A
|
||||
@A
|
||||
public @interface B {
|
||||
@interface B {
|
||||
|
||||
@AliasFor(annotation = A.class)
|
||||
int value();
|
||||
|
||||
Reference in New Issue
Block a user