Skip to content

Migrate deprecated JUnit 4 TemporaryFolder to JUnit 5 @TempDir#5799

Closed
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260716-050252-133f4b23
Closed

Migrate deprecated JUnit 4 TemporaryFolder to JUnit 5 @TempDir#5799
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260716-050252-133f4b23

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 five issues share the same MAJOR severity rule (java:S5738) with identical remediation: remove deprecated APIs marked for removal. These changes form a cohesive migration effort across core java-frontend test modules, delivering high-value automation ROI while maintaining a focused, manageable scope.

Replaces deprecated JUnit 4 TemporaryFolder and @EnableRuleMigrationSupport (marked for removal) with JUnit 5's native @tempdir annotation across five test files. This eliminates MAJOR SonarQube violations and modernizes the test infrastructure to use current JUnit 5 APIs.

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:java-frontend/src/test/java/org/sonar/java/BatchGeneratorTest.java:36

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 the deprecated EnableRuleMigrationSupport class (marked for removal) and the JUnit 4 TemporaryFolder class, replacing them with the JUnit 5 native @TempDir annotation import. This directly addresses the usage of the deprecated EnableRuleMigrationSupport class that was flagged as a code smell for calling a deprecated class marked for removal.

--- a/java-frontend/src/test/java/org/sonar/java/BatchGeneratorTest.java
+++ b/java-frontend/src/test/java/org/sonar/java/BatchGeneratorTest.java
@@ -27,2 +26,1 @@ import org.junit.jupiter.api.Test;
-import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.io.TempDir;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java:86

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 org.junit.Rule, which was needed for the JUnit 4 @Rule annotation used with TemporaryFolder. This import is no longer needed because the deprecated @EnableRuleMigrationSupport (marked for removal) and the JUnit 4 @Rule/TemporaryFolder pattern are being replaced with JUnit 5's @TempDir.

--- a/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java
+++ b/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java
@@ -26,1 +25,0 @@ import org.eclipse.core.runtime.OperationCanceledException;
-import org.junit.Rule;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.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

Adds the import for java.nio.file.Path, which is needed because the deprecated TemporaryFolder (from JUnit 4 migration support) is being replaced with JUnit 5's @TempDir annotation that uses Path instead. This supports the removal of the deprecated @EnableRuleMigrationSupport class that was marked for removal.

--- a/java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.java
+++ b/java-frontend/src/test/java/org/sonar/java/ast/visitors/SonarSymbolTableVisitorTest.java
@@ -19,0 +20,1 @@ import java.io.File;
+import java.nio.file.Path;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java:53

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

Adds the import for java.nio.file.Path, which is needed because the deprecated TemporaryFolder (JUnit 4 rule used via @EnableRuleMigrationSupport, which is a deprecated class marked for removal) is being replaced with JUnit 5's @tempdir that uses Path instead of File. This supports the removal of the deprecated @EnableRuleMigrationSupport usage at line 53 of SyntaxHighlighterVisitorTest.java.

--- a/java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java
+++ b/java-frontend/src/test/java/org/sonar/java/ast/visitors/SyntaxHighlighterVisitorTest.java
@@ -21,0 +22,1 @@ import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
java:S5738 - Remove this call to a deprecated class, it has been marked for removal. • MAJORView issue

Location: java:java-frontend/src/test/java/org/sonar/java/model/JParserReleasingJarsTest.java:34

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

Adds the import for java.nio.file.Path, which is needed to support the migration from the deprecated TemporaryFolder (used with @EnableRuleMigrationSupport, which is marked for removal) to JUnit 5's @tempdir annotation that uses Path instead.

--- a/java-frontend/src/test/java/org/sonar/java/model/JParserReleasingJarsTest.java
+++ b/java-frontend/src/test/java/org/sonar/java/model/JParserReleasingJarsTest.java
@@ -20,0 +21,1 @@ import java.io.File;
+import java.nio.file.Path;

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ9kMueAg304P0Ql8LLD for java:S5738 rule
- AZ9kMufag304P0Ql8LLE for java:S5738 rule
- AZ9kMuWEg304P0Ql8LLA for java:S5738 rule
- AZ9kMucYg304P0Ql8LLC for java:S5738 rule
- AZ9kMua6g304P0Ql8LLB for java:S5738 rule

Generated by SonarQube Agent (task: 5f83de3c-1584-46cd-bd40-570b534fdb27)
@vdiez

vdiez commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

already addressed in #5796

@vdiez vdiez closed this Jul 16, 2026
@vdiez
vdiez deleted the remediate-master-20260716-050252-133f4b23 branch July 16, 2026 07:09
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.

2 participants