Skip to content

Commit

Permalink
8213905: reflection not working for type annotations applied to excep…
Browse files Browse the repository at this point in the history
…tion types in the inner class constructor

Reviewed-by: jlahoda
  • Loading branch information
Vicente Romero committed Jan 26, 2022
1 parent 295c047 commit 2eab86b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -132,7 +132,8 @@ public static AnnotatedType[] buildAnnotatedTypes(byte[] rawAnnotations,
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;
}
}
Expand Down
17 changes: 13 additions & 4 deletions test/jdk/java/lang/annotation/TypeAnnotationReflection.java
Expand Up @@ -39,7 +39,8 @@ public static void main(String[] args) throws Exception {
testReturnType();
testNested();
testArray();
testRunException();
testRunException(TestClassException.class.getDeclaredMethod("foo", (Class<?>[])null));
testRunException(Outer2.TestClassException2.class.getDeclaredConstructor(Outer2.class));
testClassTypeVarBounds();
testMethodTypeVarBounds();
testFields();
Expand Down Expand Up @@ -142,9 +143,8 @@ private static void testArray() throws Exception {
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;
Expand Down Expand Up @@ -624,6 +624,15 @@ public Object foo() throws @TypeAnno("RE") @TypeAnno2("RE2") RuntimeException,
}
}

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 > {
Expand Down

1 comment on commit 2eab86b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.