Skip to content

Remove unnecessary thrown Exception declarations from test methods#414

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260711-050254-7a54713a
Open

Remove unnecessary thrown Exception declarations from test methods#414
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260711-050254-7a54713a

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? Rule java:S1130 targets unreachable thrown exception declarations, a high-confidence automated fix with clear correctness. Three instances were identified across CoverageTest.java and FlexPluginTest.java, forming a cohesive group of related issues suitable for a single focused change.

This change fixes three SonarQube code smell violations (java:S1130) by removing superfluous 'throws Exception' declarations from test methods that do not actually throw checked exceptions. Cleaning up these unnecessary exception declarations improves code readability and reduces compiler noise without affecting functionality.

View Project in SonarCloud


Fixed Issues

java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue 1
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue 2

Location: its/plugin/src/test/java/com/sonar/it/flex/CoverageTest.java:57

Why is this an issue?

Superfluous exceptions within throws clauses have negative effects on the readability and maintainability of the code. An exception in a throws clause is superfluous if it is:

What changed

Removes the superfluous 'throws Exception' declaration from the method 'report_paths_can_have_multiple_values()' at line 57 of CoverageTest.java. The method body does not actually throw any checked exception, so the 'throws Exception' clause was unnecessary and negatively impacted code readability. This also addresses the duplicate report of the same superfluous exception declaration issue at the same location.

--- a/its/plugin/src/test/java/com/sonar/it/flex/CoverageTest.java
+++ b/its/plugin/src/test/java/com/sonar/it/flex/CoverageTest.java
@@ -57,1 +57,1 @@ public class CoverageTest {
-  public void report_paths_can_have_multiple_values() throws Exception {
+  public void report_paths_can_have_multiple_values() {
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue

Location: sonar-flex-plugin/src/test/java/org/sonar/plugins/flex/FlexPluginTest.java:32

Why is this an issue?

Superfluous exceptions within throws clauses have negative effects on the readability and maintainability of the code. An exception in a throws clause is superfluous if it is:

What changed

Removes the superfluous 'throws Exception' declaration from the testGetExtensions() method, since no exception is actually thrown by the method body. This addresses the code smell about declaring thrown exceptions that cannot be thrown from the method's body.

--- a/sonar-flex-plugin/src/test/java/org/sonar/plugins/flex/FlexPluginTest.java
+++ b/sonar-flex-plugin/src/test/java/org/sonar/plugins/flex/FlexPluginTest.java
@@ -32,1 +32,1 @@ public class FlexPluginTest {
-  public void testGetExtensions() throws Exception {
+  public void testGetExtensions() {

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZggADGcxdvKFWvLKVB2 for java:S1130 rule
- AZggADKmxdvKFWvLKVCO for java:S1130 rule
- AZggADKmxdvKFWvLKVCP for java:S1130 rule

Generated by SonarQube Agent (task: b37f5bad-7682-4cb1-bfec-d16c0cec2098)
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