Skip to content

Replace try-catch with assertDoesNotThrow in SuppressWarningFilterSeTest#115

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260613-050240-366682b8
Open

Replace try-catch with assertDoesNotThrow in SuppressWarningFilterSeTest#115
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260613-050240-366682b8

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

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

Why these issues? This change addresses a SonarQube code quality issue in the test file SuppressWarningFilterSeTest.java. While the issue is in test code rather than production code, it represents a straightforward improvement that modernizes the testing pattern to use JUnit's recommended assertion method.

Replaced a try-catch block with assertDoesNotThrow() in a test method to improve readability and follow JUnit best practices. This also removes the unnecessary InvocationTargetException import that was only used in the deprecated pattern.

View Project in SonarCloud


Fixed Issues

java:S8714 - Use assertDoesNotThrow() instead of try/catch and fail() in the catch block. • MINORView issue

Location: sonar-java-symbolic-execution:java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/filters/SuppressWarningFilterSeTest.java:165

Why is this an issue?

Modern assertion libraries have made the clunky try-fail-catch pattern obsolete by introducing cleaner alternatives. For example, starting with JUnit 5, JUnit Jupiter provides assertThrows and assertDoesNotThrow. AssertJ offers similar methods.

What changed

Removes the import of InvocationTargetException which is no longer needed after replacing the try-catch block with assertDoesNotThrow. The try-catch pattern that caught InvocationTargetException (among other exceptions) and called Fail.fail() has been eliminated, so this import is no longer necessary.

--- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/filters/SuppressWarningFilterSeTest.java
+++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/filters/SuppressWarningFilterSeTest.java
@@ -21,1 +20,0 @@ import java.io.File;
-import java.lang.reflect.InvocationTargetException;

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ6v0pNt6JKQzmjWaP0J for java:S8714 rule

Generated by SonarQube Agent (task: 57c6b129-5e48-47d3-a7e0-938c85cc2aa5)
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