]> source.dussan.org Git - pf4j.git/commitdiff
Fix StackOverFlow error on Kotlin classes without @Extension (#595) master
authorMichael Rittmeister <dr@schlau.bi>
Mon, 11 Nov 2024 21:20:34 +0000 (22:20 +0100)
committerGitHub <noreply@github.com>
Mon, 11 Nov 2024 21:20:34 +0000 (23:20 +0200)
pf4j/pom.xml
pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java

index 7061db64af2e84e8b40bae2f7873283ddd34676f..9286d7e524e79f3f7e06eb70bfa59b10607a48e4 100644 (file)
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib</artifactId>
+            <version>2.0.21</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
index 59488ba34aa278cfae5cfdd28d4d415faa238af0..caa415f66d8f4c8b25e1fe8a37baa6ad302a652d 100644 (file)
@@ -358,7 +358,12 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
         // search recursively through all annotations
         for (Annotation annotation : clazz.getAnnotations()) {
             Class<? extends Annotation> annotationClass = annotation.annotationType();
-            if (!annotationClass.getName().startsWith("java.lang.annotation")) {
+            if (!annotationClass.getName().startsWith("java.lang.annotation") && !annotationClass.getName().startsWith("kotlin")) {
+                // In case an annotation is annotated with itself,
+                // an example would be @Target, which is ignored by the check above
+                // however, other libraries might do similar things
+                if (annotationClass.equals(clazz)) continue;
+
                 Extension extensionAnnotation = findExtensionAnnotation(annotationClass);
                 if (extensionAnnotation != null) {
                     return extensionAnnotation;
index 1e4b5ebb0e1927a0b45a590884c4e51cef4cffd8..5d31f5ab7741edfd45eb16355d38cc763210e106 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.pf4j;
 
+import kotlin.sequences.Sequence;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
@@ -274,4 +275,11 @@ public class AbstractExtensionFinderTest {
         Assertions.assertNull(extension);
     }
 
+    // This is a regression test, as this caused an StackOverflowError with the previous implementation
+    @Test
+    public void runningOnNonExtensionKotlinClassDoesNotThrowException() {
+        Extension result = AbstractExtensionFinder.findExtensionAnnotation(Sequence.class);
+
+        Assertions.assertNull(result);
+    }
 }