Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.4] Fix indexing bridge methods with type annotations on type parameters #154

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<dependency>
<groupId>org.jboss.jandex</groupId>
<artifactId>typeannotation-test</artifactId>
<version>1.8</version>
<version>1.9</version>
<type>jar</type>
<scope>test</scope>
</dependency>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,12 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati

BooleanHolder genericsRequired = new BooleanHolder();
BooleanHolder bridgeIncompatible = new BooleanHolder();

if (typeTarget.usage() == TypeTarget.Usage.TYPE_PARAMETER
|| typeTarget.usage() == TypeTarget.Usage.TYPE_PARAMETER_BOUND) {
genericsRequired.bool = true;
}

ArrayList<PathElement> pathElements = processTargetPath(data, genericsRequired, bridgeIncompatible);
AnnotationInstance annotation = processAnnotation(data, typeTarget);
return new TypeAnnotationState(typeTarget, annotation, pathElements, genericsRequired.bool, bridgeIncompatible.bool);
Expand Down
83 changes: 83 additions & 0 deletions src/test/java/org/jboss/jandex/test/BridgeMethodTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.jboss.jandex.test;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Indexer;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;
Expand All @@ -28,6 +29,10 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

public class BridgeMethodTestCase {

Expand Down Expand Up @@ -134,4 +139,82 @@ private void verifyMethodSignature(
Assert.fail("At least one '" + methodName + "' method is expected in " + klass);
}
}

@Test
public void returnType() throws IOException {
DotName nullable = DotName.createSimple("test.Nullable");
DotName untainted = DotName.createSimple("test.Untainted");

Indexer indexer = new Indexer();
ClassInfo clazz = indexer.index(getClassBytes("test/BridgeMethods$Subclass.class"));
for (MethodInfo method : filterMethods(clazz, "typeVariable")) {
if (method.returnType().name().equals(DotName.createSimple(Collection.class.getName()))) {
// bridge method
Assert.assertTrue(isBridge(method));
Assert.assertEquals(Type.Kind.CLASS, method.returnType().kind());
Assert.assertTrue(method.typeParameters().isEmpty());

Assert.assertNotNull(method.annotation(nullable));
Assert.assertEquals(Type.Kind.VOID, method.annotation(nullable).target().asType().target().kind());

Assert.assertNotNull(method.annotation(untainted));
Assert.assertEquals(Type.Kind.VOID, method.annotation(untainted).target().asType().target().kind());
} else if (method.returnType().name().equals(DotName.createSimple(Set.class.getName()))) {
// actual overridden method
Assert.assertFalse(isBridge(method));
Assert.assertEquals(Type.Kind.PARAMETERIZED_TYPE, method.returnType().kind());
Assert.assertFalse(method.typeParameters().isEmpty());

Assert.assertNotNull(method.annotation(nullable));
Assert.assertEquals(Type.Kind.CLASS, method.annotation(nullable).target().asType().target().kind());
Assert.assertNotNull(method.typeParameters().get(0).asTypeVariable()
.bounds().get(0).annotation(nullable));

Assert.assertNotNull(method.annotation(untainted));
Assert.assertEquals(Type.Kind.TYPE_VARIABLE, method.annotation(untainted).target().asType().target().kind());
Assert.assertNotNull(method.typeParameters().get(0).asTypeVariable().annotation(untainted));
} else {
Assert.fail();
}
}

for (MethodInfo method : filterMethods(clazz, "wildcard")) {
if (method.returnType().name().equals(DotName.createSimple(Collection.class.getName()))) {
// bridge method
Assert.assertTrue(isBridge(method));
Assert.assertEquals(Type.Kind.CLASS, method.returnType().kind());

Assert.assertNotNull(method.annotation(nullable));
Assert.assertEquals(Type.Kind.VOID, method.annotation(nullable).target().asType().target().kind());

Assert.assertNotNull(method.annotation(untainted));
Assert.assertEquals(Type.Kind.VOID, method.annotation(untainted).target().asType().target().kind());
} else if (method.returnType().name().equals(DotName.createSimple(Set.class.getName()))) {
// actual overridden method
Assert.assertFalse(isBridge(method));
Assert.assertEquals(Type.Kind.PARAMETERIZED_TYPE, method.returnType().kind());

Assert.assertNotNull(method.annotation(nullable));
Assert.assertEquals(Type.Kind.CLASS, method.annotation(nullable).target().asType().target().kind());
Assert.assertNotNull(method.returnType().asParameterizedType().arguments().get(0)
.asWildcardType().extendsBound().annotation(nullable));

Assert.assertNotNull(method.annotation(untainted));
Assert.assertEquals(Type.Kind.WILDCARD_TYPE, method.annotation(untainted).target().asType().target().kind());
Assert.assertNotNull(method.returnType().asParameterizedType().arguments().get(0).annotation(untainted));
} else {
Assert.fail();
}
}
}

private List<MethodInfo> filterMethods(ClassInfo clazz, String methodName) {
List<MethodInfo> result = new ArrayList<MethodInfo>();
for (MethodInfo method : clazz.methods()) {
if (methodName.equals(method.name())) {
result.add(method);
}
}
return result;
}
}