SONARJAVA-6635 Implement S9068: @ApplicationScoped should be preferred over @Singleton in Quarkus applications#5824
SONARJAVA-6635 Implement S9068: @ApplicationScoped should be preferred over @Singleton in Quarkus applications#5824NoemieBenard wants to merge 10 commits into
@ApplicationScoped should be preferred over @Singleton in Quarkus applications#5824Conversation
| private static boolean hasJustifyingComment(AnnotationTree annotation) { | ||
| return annotation.firstToken().trivias().stream() | ||
| .anyMatch(trivia -> trivia.comment().toLowerCase(java.util.Locale.ROOT).contains("singleton")); | ||
| } |
There was a problem hiding this comment.
💡 Quality: Justifying-comment heuristic matches any comment containing 'singleton'
The check suppresses an issue whenever a preceding comment merely contains the substring "singleton" (case-insensitive). Unrelated comments such as // TODO: remove this old singleton pattern will silently suppress a legitimate finding (false negative), and the match is not tied to an actual justification. Consider requiring a more explicit marker or documenting the heuristic's looseness; at minimum this behavior should be covered by a test asserting the intent.
Was this helpful? React with 👍 / 👎
| public List<Tree.Kind> nodesToVisit() { | ||
| return List.of(Tree.Kind.CLASS, Tree.Kind.METHOD); | ||
| } | ||
|
|
||
| @Override | ||
| public void visitNode(Tree tree) { | ||
| ModifiersTree modifiers = tree instanceof ClassTree classTree | ||
| ? classTree.modifiers() | ||
| : ((MethodTree) tree).modifiers(); |
There was a problem hiding this comment.
💡 Edge Case: Rule ignores @singleton on enums, records and interfaces
nodesToVisit registers only Tree.Kind.CLASS and Tree.Kind.METHOD. A CDI bean declared as a record (or enum) is a distinct tree kind (RECORD/ENUM), so @Singleton on such declarations is never flagged. If those are intended targets, add the relevant kinds; otherwise consider documenting the intentional scope limitation with a test.
Was this helpful? React with 👍 / 👎
CI failed: The build failed due to duplicate class definitions in the new test source file and a Java version incompatibility in the integration test environment.OverviewThe CI build failed due to a combination of a compilation error caused by duplicate class names in the new test source file and a configuration issue in the integration test environment where the Java version was insufficient for the sonar-maven-plugin. FailuresDuplicate Class Compilation Error (confidence: high)
Java Version Incompatibility (confidence: high)
Summary
Code Review 👍 Approved with suggestions 2 resolved / 4 findingsImplements S9068 to prefer 💡 Quality: Justifying-comment heuristic matches any comment containing 'singleton'The check suppresses an issue whenever a preceding comment merely contains the substring "singleton" (case-insensitive). Unrelated comments such as 💡 Edge Case: Rule ignores
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|




Summary by Gitar
S9068to encourage the use of@ApplicationScopedover@Singletonin Quarkus applications.io.quarkusimports.@Singletonis used intentionally.This will update automatically on new commits.