SONARPHP-1819 fix: remove unnecessary exception declarations and use EnumMap#1701
SONARPHP-1819 fix: remove unnecessary exception declarations and use EnumMap#1701sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZkoU-_5IsbR56mqmhGh for java:S1130 rule - AZkoU_a9IsbR56mqmhIN for java:S1130 rule - AZkoU_aeIsbR56mqmhIL for java:S1130 rule - AZkoU-96IsbR56mqmhGT for java:S1130 rule - AZkoU-9YIsbR56mqmhGQ for java:S1640 rule Generated by SonarQube Agent (task: de459768-98ee-4fb7-a50d-77c5620a1dab)
Summary
This PR addresses 5 SonarQube code smells (S1130) by removing unused The changes are minimal: 4 test methods across different test files get their throws clauses removed, and 1 line in production code switches to EnumMap initialization. All modifications are non-functional code quality improvements. What reviewers should knowWhat to review:
No functional changes — this is purely addressing SonarQube code quality issues. All changes are low-risk and self-contained.
|
|




Removed superfluous 'throws Exception' declarations from five test methods where no checked exceptions are actually thrown, improving code clarity and reducing false positives. Also converted a HashMap to EnumMap in RepeatedComplementOperatorCheck where the map keys are enum values, optimizing memory usage and type safety.
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. • MINOR • View issue
Location:
php:php-checks/src/test/java/org/sonar/php/checks/AvoidDESCheckTest.java:25Why is this an issue?
Superfluous exceptions within
throwsclauses have negative effects on the readability and maintainability of the code. An exception in athrowsclause is superfluous if it is:What changed
Removes the superfluous 'throws Exception' declaration from the defaultValue() method in AvoidDESCheckTest.java. The method body does not actually throw any checked Exception, so the throws clause was unnecessary. This fixes the code smell where a thrown exception is declared but cannot actually be thrown from the method's body.
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINOR • View issue
Location:
php:php-checks/src/test/java/org/sonar/php/checks/LocalVariableShadowsClassFieldCheckTest.java:25Why is this an issue?
Superfluous exceptions within
throwsclauses have negative effects on the readability and maintainability of the code. An exception in athrowsclause is superfluous if it is:What changed
Removes the superfluous 'throws Exception' declaration from the test method 'test()' in LocalVariableShadowsClassFieldCheckTest.java. The method body does not actually throw any checked exception, so declaring 'throws Exception' is unnecessary and reduces code readability. By changing the method signature from 'void test() throws Exception' to 'void test()', the code smell about a declared thrown exception that cannot be thrown from the method's body is resolved.
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINOR • View issue
Location:
php:php-checks/src/test/java/org/sonar/php/checks/SSLHostVerificationDisabledCheckTest.java:24Why is this an issue?
Superfluous exceptions within
throwsclauses have negative effects on the readability and maintainability of the code. An exception in athrowsclause is superfluous if it is:What changed
Removes the superfluous 'throws Exception' declaration from the test() method signature. 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.
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINOR • View issue
Location:
php:php-checks/src/test/java/org/sonar/php/checks/phpini/FileUploadsCheckTest.java:38Why is this an issue?
Superfluous exceptions within
throwsclauses have negative effects on the readability and maintainability of the code. An exception in athrowsclause is superfluous if it is:What changed
Removes the superfluous 'throws Exception' declaration from the 'fileIssue()' 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.
java:S1640 - Convert this Map to an EnumMap. • MINOR • View issue
Location:
php:php-checks/src/main/java/org/sonar/php/checks/RepeatedComplementOperatorCheck.java:45Why is this an issue?
If all the keys in a
Mapare values from a single enum, it is recommended to use anEnumMapas the specific implementation. AnEnumMap, which has the advantage of knowing all possible keys in advance, is more efficient compared to other implementations, as it can use a simple array as its underlying data structure.What changed
Replaces the import of
HashMapwithEnumMapto support the change from using aHashMapto anEnumMapfor aMapwhose keys are enum values (Kind). This is necessary for the code to compile after the main fix in the other hunk.SonarQube Remediation Agent uses AI. Check for mistakes.