diff --git a/pom.xml b/pom.xml index 3af7f174..82ee09fa 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ org.jboss.jandex typeannotation-test - 1.9 + 1.10 jar test diff --git a/src/main/java/org/jboss/jandex/Indexer.java b/src/main/java/org/jboss/jandex/Indexer.java index 209801c3..abb520bd 100644 --- a/src/main/java/org/jboss/jandex/Indexer.java +++ b/src/main/java/org/jboss/jandex/Indexer.java @@ -270,6 +270,7 @@ private static void skipFully(InputStream s, long n) throws IOException { private ArrayList elementAnnotations; private IdentityHashMap signaturePresent; private List signatures; + private int classSignatureIndex; private Map innerClasses; private IdentityHashMap> typeAnnotations; private List methods; @@ -320,6 +321,7 @@ private void initClassFields() { elementAnnotations = new ArrayList(); signaturePresent = new IdentityHashMap(); signatures = new ArrayList(); + classSignatureIndex = -1; typeAnnotations = new IdentityHashMap>(); // in bytecode, record components are stored as class attributes, @@ -1386,6 +1388,9 @@ private void processExceptions(DataInputStream data, MethodInfo target) throws I private void processSignature(DataInputStream data, AnnotationTarget target) throws IOException { String signature = decodeUtf8Entry(data.readUnsignedShort()); + if (target instanceof ClassInfo) { + classSignatureIndex = signatures.size(); + } signatures.add(signature); signatures.add(target); signaturePresent.put(target, null); @@ -1401,14 +1406,18 @@ private void parseClassSignature(String signature, ClassInfo clazz) { private void applySignatures() { int end = signatures.size(); - // Class signature is always the last element and should be processed first - Object last = end > 1 ? signatures.get(end - 1) : null; - if (last instanceof ClassInfo) { - parseClassSignature((String)signatures.get(end - 2), (ClassInfo)last); - end -= 2; + // Class signature should be processed first to establish class type parameters + if (classSignatureIndex >= 0) { + String elementSignature = (String) signatures.get(classSignatureIndex); + Object element = signatures.get(classSignatureIndex + 1); + parseClassSignature(elementSignature, (ClassInfo) element); } for (int i = 0; i < end; i += 2) { + if (i == classSignatureIndex) { + continue; + } + String elementSignature = (String) signatures.get(i); Object element = signatures.get(i + 1); @@ -1995,6 +2004,7 @@ public ClassInfo index(InputStream stream) throws IOException { elementAnnotations = null; innerClasses = null; signatures = null; + classSignatureIndex = -1; signaturePresent = null; } } diff --git a/src/test/java/org/jboss/jandex/test/RecordTestCase.java b/src/test/java/org/jboss/jandex/test/RecordTestCase.java index bd5538fc..35620bf3 100644 --- a/src/test/java/org/jboss/jandex/test/RecordTestCase.java +++ b/src/test/java/org/jboss/jandex/test/RecordTestCase.java @@ -77,7 +77,7 @@ public void testRecordComponentHasAnnotation() { assertEquals("name", componentAnnos.get(0).target().asRecordComponent().name()); assertEquals("nameComponent", componentAnnos.get(0).value().asString()); - assertEquals(2, rec.recordComponents().size()); + assertEquals(3, rec.recordComponents().size()); RecordComponentInfo idComponent = rec.recordComponent("id"); assertNotNull(idComponent); @@ -144,6 +144,16 @@ public void testComponentAccessorHasAnnotation() { assertEquals("nameAccessor", nameAnnotations.get(1).value().asString()); } + @Test + public void testRecordSignatureProcessed() { + ClassInfo rec = index.getClassByName(DotName.createSimple("test.RecordExample")); + assertNotNull(rec); + assertTrue(rec.isRecord()); + + assertEquals(1, rec.typeParameters().size()); + assertEquals("T", rec.typeParameters().get(0).identifier()); + } + private Index buildIndex() throws IOException { Indexer indexer = new Indexer(); indexer.index(getClass().getClassLoader().getResourceAsStream("test/RecordExample.class"));