Skip to content

SLLS-548 fix: resolve 6 SonarQube code quality issues#710

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260524-050213-d34961cf
Open

SLLS-548 fix: resolve 6 SonarQube code quality issues#710
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260524-050213-d34961cf

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

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

Replaces deprecated URL constructors with URI.create().toURL(), fixes static field naming conventions to use camelCase, adds missing import for Paths, and refactors a loop to eliminate multiple break/continue statements. These changes improve code quality and align with current Java best practices.

View Project in SonarCloud


Fixed Issues

java:S1874 - Remove this use of "URL"; it is deprecated. • MINORView issue

Location: sonarlint-language-server:src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java:267

Why is this an issue?

Code is sometimes annotated as deprecated by developers maintaining libraries or APIs to indicate that the method, class, or other programming element is no longer recommended for use. This is typically due to the introduction of a newer or more effective alternative. For example, when a better solution has been identified, or when the existing code presents potential errors or security risks.

What changed

Removes the import of the deprecated java.net.URL class. Since all three usages of the deprecated new URL(...) constructor are being replaced with URI.create(...).toURL(), the direct import of java.net.URL is no longer needed. This supports the fix for all three deprecation warnings about using the deprecated URL constructor.

--- a/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java
+++ b/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java
@@ -32,1 +31,0 @@ import java.net.URISyntaxException;
-import java.net.URL;
java:S1874 - Remove this use of "URL"; it is deprecated. • MINORView issue

Location: sonarlint-language-server:src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java:875

Why is this an issue?

Code is sometimes annotated as deprecated by developers maintaining libraries or APIs to indicate that the method, class, or other programming element is no longer recommended for use. This is typically due to the introduction of a newer or more effective alternative. For example, when a better solution has been identified, or when the existing code presents potential errors or security risks.

What changed

Removes the import of the deprecated java.net.URL class. Since all three usages of the deprecated new URL(...) constructor are being replaced with URI.create(...).toURL(), the direct import of java.net.URL is no longer needed. This supports the fix for all three deprecation warnings about using the deprecated URL constructor.

--- a/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java
+++ b/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java
@@ -32,1 +31,0 @@ import java.net.URISyntaxException;
-import java.net.URL;
java:S1874 - Remove this use of "URL"; it is deprecated. • MINORView issue

Location: sonarlint-language-server:src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java:890

Why is this an issue?

Code is sometimes annotated as deprecated by developers maintaining libraries or APIs to indicate that the method, class, or other programming element is no longer recommended for use. This is typically due to the introduction of a newer or more effective alternative. For example, when a better solution has been identified, or when the existing code presents potential errors or security risks.

What changed

Removes the import of the deprecated java.net.URL class. Since all three usages of the deprecated new URL(...) constructor are being replaced with URI.create(...).toURL(), the direct import of java.net.URL is no longer needed. This supports the fix for all three deprecation warnings about using the deprecated URL constructor.

--- a/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java
+++ b/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java
@@ -32,1 +31,0 @@ import java.net.URISyntaxException;
-import java.net.URL;
java:S1874 - Remove this use of "getPath"; it is deprecated. • MINORView issue

Location: sonarlint-language-server:src/test/java/org/sonarsource/sonarlint/ls/file/FolderFileSystemTests.java:104

Why is this an issue?

Code is sometimes annotated as deprecated by developers maintaining libraries or APIs to indicate that the method, class, or other programming element is no longer recommended for use. This is typically due to the introduction of a newer or more effective alternative. For example, when a better solution has been identified, or when the existing code presents potential errors or security risks.

What changed

Adds the import for java.nio.file.Paths, which is needed by the replacement code in Hunk 2 that replaces the deprecated ClientInputFile::getPath method reference with Paths.get(f.uri()).toString().

--- a/src/test/java/org/sonarsource/sonarlint/ls/file/FolderFileSystemTests.java
+++ b/src/test/java/org/sonarsource/sonarlint/ls/file/FolderFileSystemTests.java
@@ -26,0 +27,1 @@ import java.nio.file.Path;
+import java.nio.file.Paths;
java:S3008 - Rename this field "MODULE_1_ROOT_URI" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. • MINORView issue

Location: sonarlint-language-server:src/test/java/org/sonarsource/sonarlint/ls/mediumtests/JavaMediumTests.java:54

Why is this an issue?

The Java Language Specification defines a set of rules called naming conventions that apply to Java programs. These conventions provide recommendations for naming packages, classes, methods, and variables.

What changed

This hunk directly fixes the naming convention violation by renaming the static non-final fields MODULE_1_ROOT_URI and MODULE_2_ROOT_URI to module1RootUri and module2RootUri, which match the required camelCase pattern ^[a-z][a-zA-Z0-9]*$. This is the core fix for the static field naming convention code smell.

--- a/src/test/java/org/sonarsource/sonarlint/ls/mediumtests/JavaMediumTests.java
+++ b/src/test/java/org/sonarsource/sonarlint/ls/mediumtests/JavaMediumTests.java
@@ -54,2 +54,2 @@ class JavaMediumTests extends AbstractLanguageServerMediumTests {
-  private static String MODULE_1_ROOT_URI;
-  private static String MODULE_2_ROOT_URI;
+  private static String module1RootUri;
+  private static String module2RootUri;
java:S135 - Reduce the total number of break and continue statements in this loop to use at most one. • MINORView issue

Location: sonarlint-language-server:src/main/java/org/sonarsource/sonarlint/ls/java/JavaSdkUtil.java:69

Why is this an issue?

The use of break and continue statements increases the complexity of the control flow and makes it harder to understand the program logic. In order to keep a good program structure, they should not be applied more than once per loop.

What changed

This hunk restructures the loop body to eliminate the first 'continue' statement by inverting the condition. Instead of checking if the jar file is an alternative implementation and continuing (skipping), it now checks if the jar file is NOT an alternative implementation and performs the work inside a nested if-block. The logic that was previously after the two continue statements is now nested inside this condition, combining both filter checks into a single nested structure without any continue statements.

--- a/src/main/java/org/sonarsource/sonarlint/ls/java/JavaSdkUtil.java
+++ b/src/main/java/org/sonarsource/sonarlint/ls/java/JavaSdkUtil.java
@@ -71,3 +71,5 @@ public final class JavaSdkUtil {
-          if (jarFileName.equals("alt-rt.jar") || jarFileName.equals("alt-string.jar")) {
-            // filter out alternative implementations
-            continue;
+          if (!jarFileName.equals("alt-rt.jar") && !jarFileName.equals("alt-string.jar")) {
+            var realPath = toRealPathOrNull(jarFile);
+            if (realPath != null && duplicatePathFilter.add(realPath)) {
+              rootFiles.add(jarFile);
+            }

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZjr5wG89TChwHguyc6z for java:S1874 rule
- AZmEP12ibmPIH7Bq_J8m for java:S1874 rule
- AZmEP12ibmPIH7Bq_J8n for java:S1874 rule
- AZmEP12ibmPIH7Bq_J8o for java:S1874 rule
- AZjRjd_I592amupb0FQS for java:S135 rule
- AZjRjd5M592amupb0FPm for java:S3008 rule

Generated by SonarQube Agent (task: adc7064c-18ef-4014-a33b-57cf41daf851)
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title fix: resolve 6 SonarQube code quality issues SLLS-548 fix: resolve 6 SonarQube code quality issues May 24, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod Bot commented May 24, 2026

SLLS-548

@sonarqube-next
Copy link
Copy Markdown

Quality Gate failed Quality Gate failed

Failed conditions
1 New issue

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE SonarQube for IDE

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.

0 participants