Skip to content

Commit

Permalink
ArC: detect incorrect usage of javax.inject.Singleton
Browse files Browse the repository at this point in the history
- jakarta.inject.Singleton should be used instead
  • Loading branch information
mkouba authored and gsmet committed Dec 11, 2023
1 parent f7ce12b commit 0b458d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void detect(ArcConfig config, ApplicationIndexBuildItem applicationIndex, Custom
unsupported.add(new UnsupportedAnnotation("com.google.inject.Singleton", correctSingleton));
unsupported.add(new UnsupportedAnnotation("jakarta.ejb.Singleton", correctSingleton));
unsupported.add(new UnsupportedAnnotation("groovy.lang.Singleton", correctSingleton));
unsupported.add(new UnsupportedAnnotation("javax.inject.Singleton", correctSingleton));

String correctInject = "@jakarta.inject.Inject";
unsupported.add(new UnsupportedAnnotation("javax.inject.Inject", correctInject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public class WrongSingletonTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(EjbSingleton.class))
.withApplicationRoot(root -> root
.addClasses(EjbSingleton.class, GuiceProducers.class, JavaxSingleton.class))
.assertException(t -> {
Throwable rootCause = ExceptionUtil.getRootCause(t);
assertTrue(rootCause.getMessage().contains("jakarta.ejb.Singleton"), t.toString());
assertTrue(rootCause.getMessage().contains("javax.inject.Singleton"), t.toString());
assertTrue(rootCause.getMessage().contains("com.google.inject.Singleton"), t.toString());
});

Expand Down Expand Up @@ -55,4 +56,9 @@ List<String> produceEjbSingleton() {

}

@javax.inject.Singleton
static class JavaxSingleton {

}

}

0 comments on commit 0b458d0

Please sign in to comment.