Fix annotation compatibility and string duplication in HTTP client - #424
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Fix annotation compatibility and string duplication in HTTP client#424sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZnrNg4uQgHvdlpusoNV for java:S127 rule - AZnrNg4uQgHvdlpusoNW for java:S1192 rule - AZmJX1qbU8CNVV2bgk-B for java:S2638 rule Generated by SonarQube Agent (task: c436b639-2d78-4f49-ae1b-ad9f4c2e9386)
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 change resolves three SonarQube issues: adds missing @nullable import to fix annotation incompatibility with overridden methods, extracts duplicated string literal "Can not call %s" into a constant to reduce code duplication, and refactors a loop counter to prevent in-loop modification. These fixes improve code quality, maintainability, and static analysis compliance.
View Project in SonarCloud
Fixed Issues
java:S2638 - Fix the incompatibility of the annotation @ParametersAreNonnullByDefault at package level to honor @nullable of the overridden method. • CRITICAL • View issue
Location:
orchestrator-parent:sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpClient.java:91Why is this an issue?
Because a subclass instance may be cast to and treated as an instance of the superclass, overriding methods should uphold the aspects of the superclass contract that relate to the Liskov Substitution Principle. Specifically, if the parameters or return type of the superclass method are marked with any of the following:
@Nullable,@CheckForNull,@NotNull,@NonNull, and@Nonnull, then subclass parameters are not allowed to tighten the contract, and return values are not allowed to loosen it.What changed
Adds the import for
javax.annotation.Nullable, which is required by the other hunk that applies the@Nullableannotation to therouteparameter of theauthenticatemethod. Without this import, the@Nullableannotation used to fix the incompatibility between the package-level@ParametersAreNonnullByDefaultand the@Nullableannotation on the overridden method's parameter would not compile.java:S1192 - Define a constant instead of duplicating this literal "Can not call %s" 4 times. • CRITICAL • View issue
Location:
orchestrator-parent:sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpCall.java:199Why is this an issue?
Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.
What changed
Defines the constant
CANNOT_CALL_FORMATto replace the duplicated string literal "Can not call %s" that appears 4 times in the file. This constant is then referenced by other hunks that replace the inline string literals, eliminating the duplication.java:S127 - Refactor the code in order to not assign to this loop counter from within the loop body. • MAJOR • View issue
Location:
orchestrator-parent:sonar-orchestrator-http/src/main/java/com/sonar/orchestrator/http/HttpCall.java:146Why 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
Changes the for loop increment from
i++toi += 2, which absorbs the extrai++that was previously inside the loop body. This eliminates the modification of the loop counter from within the loop body, making the loop counter update happen solely in the for loop's update clause.SonarQube Remediation Agent uses AI. Check for mistakes.