Skip to content

Remove deprecated classes and APIs marked for removal#5808

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260717-050310-d323b6dd
Open

Remove deprecated classes and APIs marked for removal#5808
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260717-050310-d323b6dd

Conversation

@sonarqube-agent

Copy link
Copy Markdown

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

Why these issues? All 5 issues share the same high-priority rule (java:S5738) identifying deprecated APIs marked for removal, making them ideal candidates for a unified fix. Addressing these issues reduces technical debt and prevents compilation failures in future Java versions where these deprecated classes will be completely removed.

This change resolves 5 SonarQube java:S5738 violations by removing deprecated APIs across multiple test files. The fixes include eliminating the deprecated LogTesterJUnit5 class, replacing Paths.get() with Path.of(), and removing the deprecated @tempdir field-injection pattern—all of which are marked for removal in future Java versions.

View Project in SonarCloud


Fixed Issues

java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java:14

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

Removes the import of LogTesterJUnit5 (from org.sonar.api.testfixtures.log) and its related imports (RegisterExtension, Level). LogTesterJUnit5 is a deprecated class marked for removal. By removing these imports, the code no longer references the deprecated class, which is necessary to resolve the static analysis warning about using a deprecated class marked for removal.

--- a/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java
+++ b/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java
@@ -8,3 +7,0 @@ import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.slf4j.event.Level;
-import org.sonar.api.testfixtures.log.LogTesterJUnit5;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java:14

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

Removes the import statements for LogTesterJUnit5 and related classes (RegisterExtension, Level). LogTesterJUnit5 is a deprecated class marked for removal, and this hunk removes the imports that support its usage, contributing to eliminating the deprecated class reference.

--- a/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java
+++ b/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java
@@ -8,3 +7,0 @@ import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.slf4j.event.Level;
-import org.sonar.api.testfixtures.log.LogTesterJUnit5;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java:45

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

Removes the import of java.nio.file.Paths, which is the deprecated class marked for removal. Since the code is migrated to use Path.of() instead of Paths.get(), this import is no longer needed. This supports the fix for the static analysis warning about calling a deprecated class that has been marked for removal.

--- a/external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java
+++ b/external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java
@@ -22,1 +21,0 @@ import java.nio.file.Path;
-import java.nio.file.Paths;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java:46

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

Removes the import of java.nio.file.Paths, which is a deprecated class marked for removal. This import is no longer needed because the code now uses Path.of() instead of Paths.get(), addressing the static analysis warning about using a deprecated class marked for removal at line 46 of SpotBugsSensorTest.java.

--- a/external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java
+++ b/external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java
@@ -22,1 +21,0 @@ import java.nio.file.Path;
-import java.nio.file.Paths;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/FilesUtilsTest.java:30

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

Removes the deprecated @tempdir field-level annotation at line 30, which was flagged as using a deprecated class marked for removal. By removing this field declaration, the code no longer uses the deprecated field-injection pattern of @tempdir, addressing the static analysis warning about calling a deprecated class that has been marked for removal.

--- a/java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/FilesUtilsTest.java
+++ b/java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/FilesUtilsTest.java
@@ -30,2 +29,0 @@ class FilesUtilsTest {
-  @TempDir
-  public Path temp;

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ9kMwJag304P0Ql8LLG for java:S5738 rule
- AZ9kMwHgg304P0Ql8LLF for java:S5738 rule
- AZ9kMwUBg304P0Ql8LLI for java:S5738 rule
- AZ9kMwUqg304P0Ql8LLJ for java:S5738 rule
- AZ9kMwOrg304P0Ql8LLH for java:S5738 rule

Generated by SonarQube Agent (task: dca7a97c-9b1b-4d59-a6ad-aa88c8e8bb1b)
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