Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArC: detect incorrect usage of javax.inject.Singleton #37648

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we handle @ApplicationScoped and friends somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, but it's not very common that the javax.enterprise:cdi-api is on the classpath, unlike javax.inject...


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 {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import java.util.function.Consumer;

import javax.inject.Singleton;

import jakarta.enterprise.event.Observes;
import jakarta.inject.Singleton;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cescoffier To be honest - I don't understand what is the MyObserver used for?


import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.StringAsset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import java.io.File;
import java.util.function.Consumer;

import javax.inject.Singleton;

import jakarta.enterprise.event.Observes;
import jakarta.inject.Singleton;

import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import java.util.function.Consumer;

import javax.inject.Singleton;

import jakarta.enterprise.event.Observes;
import jakarta.inject.Singleton;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.StringAsset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import java.io.File;
import java.util.function.Consumer;

import javax.inject.Singleton;

import jakarta.enterprise.event.Observes;
import jakarta.inject.Singleton;

import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import java.io.File;
import java.util.function.Consumer;

import javax.inject.Singleton;

import jakarta.enterprise.event.Observes;
import jakarta.inject.Singleton;

import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers;
Expand Down
Loading