Skip to content

Commit

Permalink
Merge pull request #202 from Ladicek/signature-parser-fix
Browse files Browse the repository at this point in the history
Fix wrong type parameter sharing in generic signature parser
  • Loading branch information
Ladicek authored May 16, 2022
2 parents 95177d5 + ada14ab commit d5ed119
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class GenericSignatureParser {
*
*/
// @formatter:on
private static WildcardType UNBOUNDED_WILDCARD = new WildcardType(null, true);
private static final WildcardType UNBOUNDED_WILDCARD = new WildcardType(null, true);
private String signature;
private int pos;
private NameTable names;
Expand Down Expand Up @@ -245,6 +245,7 @@ ClassSignature parseClassSignature(String signature) {
this.signature = signature;
this.typeParameters = this.classTypeParameters;
this.typeParameters.clear();
this.elementTypeParameters.clear();
this.pos = 0;
Type[] parameters = parseTypeParameters();
Type superClass = names.intern(parseClassTypeSignature());
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ public ClassSummary indexWithSummary(InputStream stream) throws IOException {
* @return the master index for all scanned class streams
*/
public Index complete() {
initIndexMaps();
initIndexMaps(); // if no class was indexed before calling `complete()`

propagateTypeParameterBounds();

Expand Down
43 changes: 43 additions & 0 deletions core/src/test/java/org/jboss/jandex/test/SignatureSharingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jboss.jandex.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Iterator;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.junit.jupiter.api.Test;

public class SignatureSharingTest {
public interface WithMethodSignature {
<E extends Runnable> E method(E arg);
}

public interface WithClassSignature<E extends Exception> extends Iterator<E> {
}

@Test
public void classSignatureOnly() throws Exception {
test(Index.of(WithClassSignature.class));
}

@Test
public void classSignatureBeforeMethodSignature() throws Exception {
test(Index.of(WithClassSignature.class, WithMethodSignature.class));
}

@Test
public void classSignatureAfterMethodSignature() throws Exception {
test(Index.of(WithMethodSignature.class, WithClassSignature.class));
}

private void test(Index index) {
ClassInfo clazz = index.getClassByName(WithClassSignature.class);
DotName bound = clazz.interfaceTypes().get(0).asParameterizedType() // Iterator<E>
.arguments().get(0).asTypeVariable() // E
.bounds().get(0).asClassType().name(); // E's bound

assertEquals(DotName.createSimple(Exception.class.getName()), bound);
}
}

0 comments on commit d5ed119

Please sign in to comment.