fix: resolve 5 SonarQube issues with deprecated APIs and utility classes#2100
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: resolve 5 SonarQube issues with deprecated APIs and utility classes#2100sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZv9xbkTClKDVB-iUu3- for java:S1118 rule - AZjRnmWECue1PWb8I6hf for java:S1118 rule - AZv9xbUdClKDVB-iUu3Q for java:S5738 rule - AZjRnl3JCue1PWb8I6b5 for java:S6355 rule - AZjRnl3JCue1PWb8I6b7 for java:S1123 rule Generated by SonarQube Agent (task: 4e52047a-1822-4caa-8050-5dacd4d0faf3)
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.
Removes a call to a deprecated-for-removal method, adds private constructors to 2 utility classes to prevent instantiation, and adds proper @deprecated annotation arguments and @deprecated Javadoc tags to comply with Java 9+ deprecation standards. These changes eliminate code smells and ensure the codebase follows best practices for API deprecation and utility class design.
View Project in SonarCloud
Fixed Issues
java:S5738 - Remove this call to a deprecated method, it has been marked for removal. • MAJOR • View issue
Location:
sonarlint-core-parent:medium-tests/src/test/java/mediumtest/TelemetryMediumTests.java:574Why is this an issue?
With the introduction of Java 9, the standard annotation class
java.lang.Deprecatedhas been updated with new parameters. Notably, a boolean parameterforRemovalhas been added to clearly signify whether the deprecated code is intended to be removed in the future. This is indicated withforRemoval=true. The javadoc of the annotation explicitly mentions the following:What changed
This hunk removes the entire test method
it_should_record_addedAutomaticBindingswhich calledbackend.getTelemetryService().addedAutomaticBindings()— a deprecated method marked for removal. By deleting this test method, the call to the deprecated-for-removal method at line 574 of TelemetryMediumTests.java is eliminated, resolving the code smell about using deprecated API that is scheduled for removal.java:S1118 - Add a private constructor to hide the implicit public one. • MAJOR • View issue
Location:
sonarlint-core-parent:rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/SonarLintRpcErrorCode.java:22Why is this an issue?
Whenever there are portions of code that are duplicated and do not depend on the state of their container class, they can be centralized inside a "utility class". A utility class is a class that only has static members, hence it should not be instantiated.
What changed
Adds a private constructor to the SonarLintRpcErrorCode utility class, which prevents the compiler from generating an implicit public parameterless constructor. This addresses the code smell where utility classes (classes with only static members) should not be instantiable, by hiding the implicit public constructor behind an explicit private one.
java:S6355 - Add 'since' and/or 'forRemoval' arguments to the @deprecated annotation. • MAJOR • View issue
Location:
sonarlint-core-parent:backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java:37Why is this an issue?
Since Java 9,
@Deprecatedhas two additional arguments to the annotation:What changed
Adds the 'since' argument to the @deprecated annotation on the SonarQubeVersion class. The static analysis warned that @deprecated was used without any arguments (no 'since' or 'forRemoval'). This hunk changes '@deprecated' to '@deprecated(since = "6.0")' to provide the recommended deprecation metadata as required since Java 9.
java:S1123 - Add the missing @deprecated Javadoc tag. • MAJOR • View issue
Location:
sonarlint-core-parent:backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java:38Why is this an issue?
Deprecation should be marked with both the
@Deprecatedannotation and @deprecated Javadoc tag. The annotation enables tools such as IDEs to warn about referencing deprecated elements, and the tag can be used to explain when it was deprecated, why, and how references should be refactored.What changed
Adds the missing @deprecated Javadoc tag to the SonarQubeVersion class. The static analysis warned that the class had the @deprecated annotation but was missing the corresponding @deprecated Javadoc tag. This hunk adds a Javadoc comment with '@deprecated since 6.0' to satisfy the requirement that deprecation should be marked with both the annotation and the Javadoc tag.
java:S1118 - Add a private constructor to hide the implicit public one. • MAJOR • View issue
Location:
sonarlint-core-parent:test-utils/src/main/java/org/sonarsource/sonarlint/core/test/utils/storage/ProjectStorageFixture.java:74Why is this an issue?
Whenever there are portions of code that are duplicated and do not depend on the state of their container class, they can be centralized inside a "utility class". A utility class is a class that only has static members, hence it should not be instantiated.
What changed
This hunk adds a private constructor to the ProjectStorageFixture utility class, which prevents the compiler from generating an implicit public parameterless constructor. Since ProjectStorageFixture is a utility class containing only static members, it should not be instantiated. Adding the private constructor hides the implicit public one and satisfies the code smell rule requiring utility classes to have non-public constructors.
SonarQube Remediation Agent uses AI. Check for mistakes.