Skip to content

SONARPHP-1835 fix: Remove superfluous throws Exception declarations from test methods#1716

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260529-050221-824000ce
Open

SONARPHP-1835 fix: Remove superfluous throws Exception declarations from test methods#1716
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260529-050221-824000ce

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

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

Removed unnecessary 'throws Exception' declarations from 5 test methods that don't actually throw any checked exceptions. This resolves SonarQube code smells (S1130) and improves code clarity by ensuring method signatures accurately reflect the exceptions they can throw.

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

Location: php:php-checks/src/test/java/org/sonar/php/checks/CollapsibleIfStatementCheckTest.java:25

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 test() method signature, since no exception is actually thrown from the method's body. This addresses the code smell about declaring thrown exceptions that cannot be thrown from the method's body.

--- a/php-checks/src/test/java/org/sonar/php/checks/CollapsibleIfStatementCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/CollapsibleIfStatementCheckTest.java
@@ -25,1 +25,1 @@ class CollapsibleIfStatementCheckTest {
-  void test() throws Exception {
+  void test() {
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue

Location: php:php-checks/src/test/java/org/sonar/php/checks/TooManyLinesInFileCheckTest.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 'defaultValue()' method signature. The method body does not actually throw any checked exception of type 'java.lang.Exception', so declaring it in the throws clause is unnecessary and reduces code readability. By removing it, the method signature accurately reflects the exceptions that can actually be thrown.

--- a/php-checks/src/test/java/org/sonar/php/checks/TooManyLinesInFileCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/TooManyLinesInFileCheckTest.java
@@ -32,1 +32,1 @@ class TooManyLinesInFileCheckTest {
-  void defaultValue() throws Exception {
+  void defaultValue() {
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue

Location: php:php-checks/src/test/java/org/sonar/php/checks/regex/EmptyAlternativeCheckTest.java:25

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 test() method signature, since no exception is actually thrown from the method's body. This directly addresses the code smell about declaring thrown exceptions that cannot be thrown from the method's body.

--- a/php-checks/src/test/java/org/sonar/php/checks/regex/EmptyAlternativeCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/EmptyAlternativeCheckTest.java
@@ -25,1 +25,1 @@ class EmptyAlternativeCheckTest {
-  void test() throws Exception {
+  void test() {
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue

Location: php:php-checks/src/test/java/org/sonar/php/checks/regex/ImpossibleBoundariesCheckTest.java:25

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 test method 'test()' in ImpossibleBoundariesCheckTest.java. The method body does not actually throw any checked exception, so declaring 'throws Exception' is unnecessary and reduces code readability. By removing this declaration, the method signature becomes cleaner and compliant with the rule that exceptions listed in a throws clause should actually be throwable from the method's body.

--- a/php-checks/src/test/java/org/sonar/php/checks/regex/ImpossibleBoundariesCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/ImpossibleBoundariesCheckTest.java
@@ -25,1 +25,1 @@ class ImpossibleBoundariesCheckTest {
-  void test() throws Exception {
+  void test() {
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINORView issue

Location: php:php-checks/src/test/java/org/sonar/php/checks/regex/SingleCharCharacterClassCheckTest.java:25

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 test method 'test()' in SingleCharCharacterClassCheckTest.java. The method body does not actually throw any checked exception, so the 'throws Exception' clause was unnecessary and flagged as a code smell. By removing it, the method signature accurately reflects that no checked exceptions are thrown.

--- a/php-checks/src/test/java/org/sonar/php/checks/regex/SingleCharCharacterClassCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/SingleCharCharacterClassCheckTest.java
@@ -25,1 +25,1 @@ class SingleCharCharacterClassCheckTest {
-  void test() throws Exception {
+  void test() {

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZkoU_erIsbR56mqmhIb for java:S1130 rule
- AZkoU_f1IsbR56mqmhIh for java:S1130 rule
- AZkoU_EVIsbR56mqmhG6 for java:S1130 rule
- AZkoU_EmIsbR56mqmhG7 for java:S1130 rule
- AZkoU_F2IsbR56mqmhG_ for java:S1130 rule

Generated by SonarQube Agent (task: 46878f59-b480-415f-b9ab-c27b3222c821)
@sonarqube-agent sonarqube-agent AI requested a review from petertrr May 29, 2026 05:03
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title fix: Remove superfluous throws Exception declarations from test methods SONARPHP-1835 fix: Remove superfluous throws Exception declarations from test methods May 29, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown
Contributor

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

SONARPHP-1835

@sonarqube-next
Copy link
Copy Markdown

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