diff --git a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java index e2bd327..a156fab 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java @@ -356,9 +356,11 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin // search recursively through all annotations for (Annotation annotation : clazz.getAnnotations()) { Class annotationClass = annotation.annotationType(); - Extension extensionAnnotation = findExtensionAnnotation(annotationClass); - if (extensionAnnotation != null) { - return extensionAnnotation; + if (!annotationClass.getName().startsWith("java.lang.annotation")) { + 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 74ccadb..bcf1535 100644 --- a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java @@ -37,6 +37,7 @@ import java.util.Set; import static com.google.testing.compile.CompilationSubject.assertThat; import static com.google.testing.compile.Compiler.javac; +import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.eq; @@ -217,6 +218,22 @@ public class AbstractExtensionFinderTest { assertNotNull(extension); } + @Test + public void findExtensionAnnotationThatMissing() throws Exception { + Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting, + ExtensionAnnotationProcessorTest.SpinnakerExtension_NoExtension, + ExtensionAnnotationProcessorTest.WhazzupGreeting_SpinnakerExtension); + assertThat(compilation).succeededWithoutWarnings(); + ImmutableList generatedFiles = compilation.generatedFiles(); + assertEquals(3, generatedFiles.size()); + + JavaFileObjectClassLoader classLoader = new JavaFileObjectClassLoader(); + Map> loadedClasses = classLoader.loadClasses(new ArrayList<>(generatedFiles)); + Class clazz = loadedClasses.get("test.WhazzupGreeting"); + Extension extension = AbstractExtensionFinder.findExtensionAnnotation(clazz); + assertNull(extension); + } + static class JavaFileObjectClassLoader extends ClassLoader { public Map> loadClasses(List classes) throws IOException { diff --git a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java index 652c754..f966523 100644 --- a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java +++ b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java @@ -103,6 +103,27 @@ public class ExtensionAnnotationProcessorTest { " }", "}"); + /** + * The same like {@link #SpinnakerExtension} but without {@code Extension} annotation. + */ + public static final JavaFileObject SpinnakerExtension_NoExtension = JavaFileObjects.forSourceLines( + "SpinnakerExtension", + "package test;", + "", + "import org.pf4j.Extension;", + "import java.lang.annotation.Documented;", + "import java.lang.annotation.ElementType;", + "import java.lang.annotation.Retention;", + "import java.lang.annotation.RetentionPolicy;", + "import java.lang.annotation.Target;", + "", +// "@Extension", + "@Retention(RetentionPolicy.RUNTIME)", + "@Target(ElementType.TYPE)", + "@Documented", + "public @interface SpinnakerExtension {", + "}"); + @Test public void getSupportedAnnotationTypes() { ExtensionAnnotationProcessor instance = new ExtensionAnnotationProcessor();