fix: replace Singleton pattern with Spring dependency injection#36
Open
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
Open
fix: replace Singleton pattern with Spring dependency injection#36sonarqube-agent[bot] wants to merge 1 commit intomainfrom
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
Conversation
Fixed issues: - AZDatDa65t_4Z0QD_mkB for java:S6548 rule Generated by SonarQube Agent (task: 24fd8c8b-6d52-485e-a9d4-ed9da8d4bc0c)
Author
|
|
|
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Refactored MsgTimeChecker to use Spring's dependency injection instead of the Singleton pattern (Bill Pugh implementation). This addresses the SonarQube code smell by enabling proper bean management and testability through Spring's component lifecycle management.
View Project in SonarCloud
Fixed Issues
java:S6548 - A Singleton implementation was detected. Make sure the use of the Singleton pattern is required and the implementation is the right one for the context. • INFO • View issue
Location:
async-listener/src/main/java/fr/ans/psc/asynclistener/consumer/MsgTimeChecker.java:24Why is this an issue?
While the Singleton pattern can be useful in certain situations, overusing it can have several drawbacks:
What changed
This hunk registers MsgTimeChecker as a Spring-managed bean in the test context configuration. Instead of relying on the Singleton pattern (Bill Pugh implementation with a private constructor, static holder class, and getInstance() method), MsgTimeChecker is now treated as a Spring component that can be injected via dependency injection. This is part of the refactoring away from the Singleton pattern detected in MsgTimeChecker, addressing the code smell about Singleton usage by enabling proper dependency injection in tests.
SonarQube Remediation Agent uses AI. Check for mistakes.