Repository navigation
Fix 5 SonarQube code quality violations across utility and servlet classes - #10
Open
sonarqube-agent-dev7[bot] wants to merge 1 commit into
Open
sonarqube-agent-dev7[bot] wants to merge 1 commit into
sonarqube-agent-dev7[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ-oICfUhOZFoKAWFeg0 for java:S1161 rule - AZ-oICh_hOZFoKAWFeg6 for java:S112 rule - AZ-oICh_hOZFoKAWFeg5 for java:S112 rule - AZ-oIClKhOZFoKAWFehc for java:S127 rule - AZ-oIClLhOZFoKAWFehp for java:S106 rule Generated by SonarQube Agent (task: 6c917968-4efd-472c-8aea-436f6c444fba)
Author
|
|
|
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.



This PR resolves 5 MAJOR SonarQube issues including removing a faulty loop counter assignment, replacing System.out with proper logging, adding missing @OverRide annotations, and replacing generic exceptions with specific SQLException declarations. These fixes improve code maintainability, correctness, and alignment with Java best practices.
View Project in SonarCloud
Fixed Issues
java:S127 - Refactor the code in order to not assign to this loop counter from within the loop body. • MAJOR • View issue
Location:
src/main/java/demo/security/util/DBUtils.java:82Why is this an issue?
A
forloop termination condition should test the loop counter against an invariant value that does not change during the execution of the loop. Invariant termination conditions make the program logic easier to understand and maintain.What changed
Removes the faulty inner for loop. Its header declared the counter m but tested and incremented the outer loop variable i, so the loop changed a counter the outer loop also controls. Because m never advanced, the loop added no real logic. Deleting it removes the non-invariant loop counter assignment the scanner flagged.
java:S106 - Replace this use of System.out by a logger. • MAJOR • View issue
Location:
src/main/java/demo/security/util/DBUtils.java:96Why is this an issue?
In software development, logs serve as a record of events within an application, providing crucial insights for debugging. When logging, it is essential to ensure that the logs are:
What changed
Imports java.util.logging.Level and java.util.logging.Logger. The new logger field and the guarded logging call that replace the direct System.out output depend on these imports.
java:S1161 - Add the "@OverRide" annotation above this method signature • MAJOR • View issue
Location:
src/main/java/demo/security/servlet/HomeServlet.java:30Why is this an issue?
While not mandatory, using the
@Overrideannotation on compliant methods improves readability by making it explicit that methods are overridden.What changed
The scanner flagged doPost(HttpServletRequest, HttpServletResponse) in HomeServlet because it overrides HttpServlet.doPost without saying so. This hunk adds the @OverRide annotation directly above that method. That makes the override explicit to readers. It also lets the compiler check that the method really overrides a parent method, so a signature typo would be caught at compile time.
java:S112 - Replace generic exceptions with specific library exceptions or a custom exception. • MAJOR • View issue 1
java:S112 - Replace generic exceptions with specific library exceptions or a custom exception. • MAJOR • View issue 2
Location:
src/main/java/demo/security/servlet/Insecure.java:35Why is this an issue?
Throwing generic exceptions such as
Error,RuntimeException,Throwable, andExceptionwill have a negative impact on any code trying to catch these exceptions.What changed
Adds the java.sql.SQLException import. The two method signatures need it so they can declare this specific exception instead of the generic Exception.