Incorrect handling of the optional class bound in the class type variables
vlsi opened this issue · comments
package org.jboss.jandex.test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.math.BigInteger;
public class ClassBounds<V1 extends @ClassBounds.NonNull BigInteger,
V2 extends @ClassBounds.Nullable Runnable> {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface NonNull {
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface Nullable {
}
}
Test class:
package org.jboss.jandex.test;
import org.jboss.jandex.Index;
import org.jboss.jandex.Indexer;
import org.junit.Test;
import java.io.IOException;
public class TestClassBounds {
@Test
public void classBounds() throws IOException {
Indexer indexer = new Indexer();
indexer.index(ClassBounds.class.getResourceAsStream("ClassBounds.class"));
Index index = indexer.complete();
System.out.println("subclasses");
index.printSubclasses();
System.out.println("annotations");
index.printAnnotations();
}
}
Actual error:
java.lang.ArrayIndexOutOfBoundsException: 1
at org.jboss.jandex.Indexer.updateTypeTarget(Indexer.java:847)
at org.jboss.jandex.Indexer.updateTypeTargets(Indexer.java:630)
at org.jboss.jandex.Indexer.index(Indexer.java:1618)
at org.jboss.jandex.test.TestClassBounds.classBounds(TestClassBounds.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
It looks like jandex misses something like openjdk/jdk@9d7f8bc
javac11 + javap gives the following:
Signature: #19 // <V1:Ljava/math/BigInteger;V2::Ljava/lang/Runnable;>Ljava/lang/Object;
SourceFile: "ClassBounds.java"
RuntimeVisibleTypeAnnotations:
0: #23(): CLASS_TYPE_PARAMETER_BOUND, param_index=0, bound_index=0
org.jboss.jandex.test.ClassBounds$NonNull
1: #24(): CLASS_TYPE_PARAMETER_BOUND, param_index=1, bound_index=1
org.jboss.jandex.test.ClassBounds$Nullable
Note that V2
signature has optional class bound (see V2::Ljava/lang/Runnable;
), however, bound_index
is 1
.
I don't know which specification declares that behavior, however, openjdk implementation seems to treat V2::Ljava/lang/Runnable;
as if it was V2:Ljava/lang/Object;:Ljava/lang/Runnable;
.
Closing as the issue duplicates #80