Skip to content

fix: resolve 5 SonarQube issues with deprecated APIs and utility classes#2100

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260529-050242-c965ceb2
Open

fix: resolve 5 SonarQube issues with deprecated APIs and utility classes#2100
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260529-050242-c965ceb2

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

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. • MAJORView issue

Location: sonarlint-core-parent:medium-tests/src/test/java/mediumtest/TelemetryMediumTests.java:574

Why is this an issue?

With the introduction of Java 9, the standard annotation class java.lang.Deprecated has been updated with new parameters. Notably, a boolean parameter forRemoval has been added to clearly signify whether the deprecated code is intended to be removed in the future. This is indicated with forRemoval=true. The javadoc of the annotation explicitly mentions the following:

What changed

This hunk removes the entire test method it_should_record_addedAutomaticBindings which called backend.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.

--- a/medium-tests/src/test/java/mediumtest/TelemetryMediumTests.java
+++ b/medium-tests/src/test/java/mediumtest/TelemetryMediumTests.java
@@ -562,9 +561,0 @@ class TelemetryMediumTests {
-  @SonarLintTest
-  void it_should_record_addedAutomaticBindings(SonarLintTestHarness harness) {
-    var backend = setupClientAndBackend(harness);
-
-    backend.getTelemetryService().addedAutomaticBindings();
-
-    await().untilAsserted(() -> assertThat(backend.telemetryFileContent().getAutoAddedBindingsCount()).isEqualTo(1));
-  }
-
java:S1118 - Add a private constructor to hide the implicit public one. • MAJORView issue

Location: sonarlint-core-parent:rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/SonarLintRpcErrorCode.java:22

Why 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.

--- a/rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/SonarLintRpcErrorCode.java
+++ b/rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/SonarLintRpcErrorCode.java
@@ -23,0 +24,4 @@ public class SonarLintRpcErrorCode {
+  private SonarLintRpcErrorCode() {
+    // utility class, not meant to be instantiated
+  }
+
java:S6355 - Add 'since' and/or 'forRemoval' arguments to the @deprecated annotation. • MAJORView issue

Location: sonarlint-core-parent:backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java:37

Why is this an issue?

Since Java 9, @Deprecated has 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.

--- a/backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java
+++ b/backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java
@@ -37,1 +40,1 @@ import static java.util.Objects.requireNonNull;
-@Deprecated
+@Deprecated(since = "6.0")
java:S1123 - Add the missing @deprecated Javadoc tag. • MAJORView issue

Location: sonarlint-core-parent:backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java:38

Why is this an issue?

Deprecation should be marked with both the @Deprecated annotation 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.

--- a/backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java
+++ b/backend/plugin-commons/src/main/java/org/sonar/api/SonarQubeVersion.java
@@ -32,0 +33,3 @@ import static java.util.Objects.requireNonNull;
+/**
+ * @deprecated since 6.0
+ */
java:S1118 - Add a private constructor to hide the implicit public one. • MAJORView issue

Location: sonarlint-core-parent:test-utils/src/main/java/org/sonarsource/sonarlint/core/test/utils/storage/ProjectStorageFixture.java:74

Why 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.

--- a/test-utils/src/main/java/org/sonarsource/sonarlint/core/test/utils/storage/ProjectStorageFixture.java
+++ b/test-utils/src/main/java/org/sonarsource/sonarlint/core/test/utils/storage/ProjectStorageFixture.java
@@ -75,0 +76,3 @@ public class ProjectStorageFixture {
+  private ProjectStorageFixture() {
+  }
+

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant