diff options
author | Michael Rittmeister <dr@schlau.bi> | 2024-11-11 22:20:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-11 23:20:34 +0200 |
commit | 3ff696d1a9b529348e186fe187a015c8075545e3 (patch) | |
tree | 19a615c5a83b43131b8e2c3189ac16a59a203f7f | |
parent | 1493fd706b0215ee057cfc1952ecb09ee047f499 (diff) | |
download | pf4j-3ff696d1a9b529348e186fe187a015c8075545e3.tar.gz pf4j-3ff696d1a9b529348e186fe187a015c8075545e3.zip |
Fix StackOverFlow error on Kotlin classes without @Extension (#595)
-rw-r--r-- | pf4j/pom.xml | 6 | ||||
-rw-r--r-- | pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java | 7 | ||||
-rw-r--r-- | pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java | 8 |
3 files changed, 20 insertions, 1 deletions
diff --git a/pf4j/pom.xml b/pf4j/pom.xml index 7061db6..9286d7e 100644 --- a/pf4j/pom.xml +++ b/pf4j/pom.xml @@ -199,6 +199,12 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib</artifactId> + <version>2.0.21</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java index 59488ba..caa415f 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java @@ -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; diff --git a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java index 1e4b5eb..5d31f5a 100644 --- a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java @@ -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); + } } |