Skip to content

SONARPHP-1838 fix: remove superfluous 'throws Exception' declarations from test methods#1717

Merged
felix-pauck-sonarsource merged 1 commit into
masterfrom
remediate-master-20260530-050220-47998fcb
Jun 1, 2026
Merged

SONARPHP-1838 fix: remove superfluous 'throws Exception' declarations from test methods#1717
felix-pauck-sonarsource merged 1 commit into
masterfrom
remediate-master-20260530-050220-47998fcb

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 across the php-checks module that were flagged by SonarQube rule S1130. These declarations were misleading since the methods do not actually throw any checked exceptions, so removing them improves code clarity and reduces false signals about exception handling.

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/GotoUseCheckTest.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 in GotoUseCheckTest.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 throws clauses should actually be thrown by the method's execution path.

--- a/php-checks/src/test/java/org/sonar/php/checks/GotoUseCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/GotoUseCheckTest.java
@@ -25,1 +25,1 @@ class GotoUseCheckTest {
-  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/RedefineConstantCheckTest.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 RedefineConstantCheckTest.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/RedefineConstantCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/RedefineConstantCheckTest.java
@@ -25,1 +25,1 @@ class RedefineConstantCheckTest {
-  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/TooManyLinesInFunctionCheckTest.java:29

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 in TooManyLinesInFunctionCheckTest.java. The method body does not actually throw any checked exception of type java.lang.Exception, so the throws 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/TooManyLinesInFunctionCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/TooManyLinesInFunctionCheckTest.java
@@ -29,1 +29,1 @@ class TooManyLinesInFunctionCheckTest {
-  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/EmptyGroupCheckTest.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 EmptyGroupCheckTest.java. The method body does not actually throw any checked exception, so declaring 'throws Exception' is unnecessary and reduces code readability. This directly addresses the code smell about removing declarations of thrown exceptions that cannot be thrown from the method's body.

--- a/php-checks/src/test/java/org/sonar/php/checks/regex/EmptyGroupCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/EmptyGroupCheckTest.java
@@ -25,1 +25,1 @@ class EmptyGroupCheckTest {
-  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/GroupReplacementCheckTest.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 GroupReplacementCheckTest.java. The method body does not actually throw any checked exception, so the 'throws Exception' clause was unnecessary and reduced code readability. By removing it, the method signature is cleaner and no longer declares an exception that cannot be thrown from the method's body.

--- a/php-checks/src/test/java/org/sonar/php/checks/regex/GroupReplacementCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/GroupReplacementCheckTest.java
@@ -25,1 +25,1 @@ class GroupReplacementCheckTest {
-  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_FNIsbR56mqmhG9 for java:S1130 rule
- AZkoU_fcIsbR56mqmhIe for java:S1130 rule
- AZkoU_fOIsbR56mqmhId for java:S1130 rule
- AZkoU_fqIsbR56mqmhIf for java:S1130 rule
- AZkoU_FkIsbR56mqmhG- for java:S1130 rule

Generated by SonarQube Agent (task: 0a7dd872-5152-4ebb-a7d5-39a6e7f962e7)
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title fix: remove superfluous 'throws Exception' declarations from test methods SONARPHP-1838 fix: remove superfluous 'throws Exception' declarations from test methods Jun 1, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown
Contributor

hashicorp-vault-sonar-prod Bot commented Jun 1, 2026

SONARPHP-1838

Copy link
Copy Markdown
Contributor

@felix-pauck-sonarsource felix-pauck-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@sonarqube-next
Copy link
Copy Markdown

sonarqube-next Bot commented Jun 1, 2026

@felix-pauck-sonarsource felix-pauck-sonarsource merged commit d4a5c43 into master Jun 1, 2026
36 of 38 checks passed
@felix-pauck-sonarsource felix-pauck-sonarsource deleted the remediate-master-20260530-050220-47998fcb branch June 1, 2026 05:30
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