Skip to content

SONARPHP-1836 fix: Remove unnecessary 'throws Exception' declarations from test methods#1714

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260528-050239-b59d6758
Open

SONARPHP-1836 fix: Remove unnecessary 'throws Exception' declarations from test methods#1714
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260528-050239-b59d6758

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

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

Removed 5 superfluous 'throws Exception' declarations from test methods in the PHP checks module that were flagged by SonarQube. These methods do not actually throw any checked exceptions, so the throws clauses were inaccurate and cluttered the code; removing them improves code clarity and resolves minor code smells.

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/CharacterBeforeOpeningPHPTagCheckTest.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 'ok()' method, since no exception is actually thrown from the method's body. This addresses the code smell where a throws clause declares an exception that cannot be thrown by any execution path of the method.

--- a/php-checks/src/test/java/org/sonar/php/checks/CharacterBeforeOpeningPHPTagCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/CharacterBeforeOpeningPHPTagCheckTest.java
@@ -32,1 +32,1 @@ class CharacterBeforeOpeningPHPTagCheckTest {
-  void ok() throws Exception {
+  void ok() {
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/NoPaddingRsaCheckTest.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 NoPaddingRsaCheckTest.java. The method body does not actually throw any checked exception, so declaring 'throws Exception' was unnecessary and flagged as a code smell. By removing the throws clause, the method signature accurately reflects that no checked exceptions are thrown.

--- a/php-checks/src/test/java/org/sonar/php/checks/NoPaddingRsaCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/NoPaddingRsaCheckTest.java
@@ -25,1 +25,1 @@ class NoPaddingRsaCheckTest {
-  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/WrongAssignmentOperatorCheckTest.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 WrongAssignmentOperatorCheckTest.java. The method body does not actually throw any checked exception, so the 'throws Exception' clause was unnecessary. This directly addresses the code smell about declaring a thrown exception that cannot be thrown from the method's body.

--- a/php-checks/src/test/java/org/sonar/php/checks/WrongAssignmentOperatorCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/WrongAssignmentOperatorCheckTest.java
@@ -25,1 +25,1 @@ class WrongAssignmentOperatorCheckTest {
-  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/EmptyStringRepetitionCheckTest.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 EmptyStringRepetitionCheckTest.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/EmptyStringRepetitionCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/EmptyStringRepetitionCheckTest.java
@@ -25,1 +25,1 @@ class EmptyStringRepetitionCheckTest {
-  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/RegexLookaheadCheckTest.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 RegexLookaheadCheckTest.java. The method body does not actually throw any checked exception, so the 'throws Exception' clause was unnecessary. 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/RegexLookaheadCheckTest.java
+++ b/php-checks/src/test/java/org/sonar/php/checks/regex/RegexLookaheadCheckTest.java
@@ -25,1 +25,1 @@ class RegexLookaheadCheckTest {
-  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_egIsbR56mqmhIa for java:S1130 rule
- AZkoU_dzIsbR56mqmhIW for java:S1130 rule
- AZkoU_EIIsbR56mqmhG5 for java:S1130 rule
- AZkoU_e-IsbR56mqmhIc for java:S1130 rule
- AZkoU_E1IsbR56mqmhG8 for java:S1130 rule

Generated by SonarQube Agent (task: e824f901-7cb1-411d-8479-8503bec541ed)
@sonarqube-agent sonarqube-agent AI requested a review from petertrr May 28, 2026 05:04
@sonarqube-agent sonarqube-agent AI deployed to sca-checking May 29, 2026 15:07 Active
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title fix: Remove unnecessary 'throws Exception' declarations from test methods SONARPHP-1836 fix: Remove unnecessary '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-1836

@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