8213905: reflection not working for type annotations applied to exception types in the inner class constructor

Reviewed-by: jlahoda
This commit is contained in:
Vicente Romero 2022-01-26 00:33:10 +00:00
parent 295c0474c4
commit 2eab86b513
2 changed files with 15 additions and 5 deletions

View File

@ -132,7 +132,8 @@ public final class TypeAnnotationParser {
Class<?> declaringClass = ctor.getDeclaringClass();
if (!declaringClass.isEnum() &&
(declaringClass.isMemberClass() &&
(declaringClass.getModifiers() & Modifier.STATIC) == 0) ) {
(declaringClass.getModifiers() & Modifier.STATIC) == 0) &&
filter == TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER) {
offset = true;
}
}

View File

@ -39,7 +39,8 @@ public class TypeAnnotationReflection {
testReturnType();
testNested();
testArray();
testRunException();
testRunException(TestClassException.class.getDeclaredMethod("foo", (Class<?>[])null));
testRunException(Outer2.TestClassException2.class.getDeclaredConstructor(Outer2.class));
testClassTypeVarBounds();
testMethodTypeVarBounds();
testFields();
@ -142,9 +143,8 @@ public class TypeAnnotationReflection {
check(((TypeAnno)annos[0]).value().equals("return4"));
}
private static void testRunException() throws Exception {
Method m = TestClassException.class.getDeclaredMethod("foo", (Class<?>[])null);
AnnotatedType[] ts = m.getAnnotatedExceptionTypes();
private static void testRunException(Executable e) throws Exception {
AnnotatedType[] ts = e.getAnnotatedExceptionTypes();
check(ts.length == 3);
AnnotatedType t;
@ -624,6 +624,15 @@ abstract class TestClassException {
}
}
class Outer2 {
abstract class TestClassException2 {
public TestClassException2() throws
@TypeAnno("RE") @TypeAnno2("RE2") RuntimeException,
NullPointerException,
@TypeAnno("AIOOBE") ArrayIndexOutOfBoundsException {}
}
}
abstract class TestClassTypeVarAndField <T extends @TypeAnno("Object1") Object
& @TypeAnno("Runnable1") @TypeAnno2("Runnable2") Runnable,
@TypeAnno("EE")EE extends @TypeAnno2("EEBound") Runnable, V > {