Fix switch case fall-through and eliminate duplicated string literals#23
Fix switch case fall-through and eliminate duplicated string literals#23sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZZmtiT12HDYqP_Xyn_N for java:S128 rule - AZZmth7f2HDYqP_Xynx6 for java:S1192 rule - AZZmth6c2HDYqP_Xynwp for java:S1192 rule - AZZmth5D2HDYqP_Xynwf for java:S2176 rule - AZZmth5D2HDYqP_Xynwa for java:S1192 rule Generated by SonarQube Agent (task: 625a1513-f758-417c-8ebc-535c074cf541)
|
|
SonarQube reviewer guideSummary: Refactor PHP XML client type conversion logic, extract magic strings to constants, and fix a control flow issue in BaseType type detection. Review Focus:
Start review at:
|



This PR resolves 5 SonarQube issues including a BLOCKER switch case fall-through bug in BaseType.java and 3 CRITICAL string literal duplication violations across multiple classes. The changes add proper control flow termination, extract duplicated string constants, and refactor a shadowed class name to improve code maintainability and prevent potential runtime bugs.
View Project in SonarCloud
Fixed Issues
java:S128 - End this switch case with an unconditional break, return or throw statement. • BLOCKER • View issue
Location:
core/src/main/java/com/webcohesion/enunciate/api/datatype/BaseType.java:51Why is this an issue?
When the execution is not explicitly terminated at the end of a switch case, it continues to execute the statements of the following case. While this is sometimes intentional, it often is a mistake which leads to unexpected behavior.
What changed
This hunk adds a
return BaseType.object;statement at the end of thecase DECLARED:block in the switch statement. Without this return statement, the DECLARED case would fall through to the next case, which is a switch case fall-through code smell. By adding an explicit return statement, the execution is properly terminated at the end of the DECLARED case, preventing unintentional fall-through behavior.java:S1192 - Define a constant instead of duplicating this literal "String" 20 times. • CRITICAL • View issue
Location:
php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java:68Why is this an issue?
Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.
What changed
Removes unused imports that were part of the original ClientClassnameForMethod class implementation. This supports the refactoring that moves the class logic to PhpClientClassnameForMethod, which fixes both the class name shadowing issue (where ClientClassnameForMethod shadowed its superclass com.webcohesion.enunciate.util.freemarker.ClientClassnameForMethod) and eliminates the duplicated "String" literals that were present in the old implementation.
java:S2176 - Rename this class. • CRITICAL • View issue
Location:
php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java:57Why is this an issue?
Two classes can have the same simple name if they are in two different packages.
What changed
Removes unused imports that were part of the original ClientClassnameForMethod class implementation. This supports the refactoring that moves the class logic to PhpClientClassnameForMethod, which fixes both the class name shadowing issue (where ClientClassnameForMethod shadowed its superclass com.webcohesion.enunciate.util.freemarker.ClientClassnameForMethod) and eliminates the duplicated "String" literals that were present in the old implementation.
java:S1192 - Define a constant instead of duplicating this literal "integer" 12 times. • CRITICAL • View issue
Location:
php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java:58Why is this an issue?
Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.
What changed
Defines the constant
INTEGER_TYPEwith value "integer" to replace all 12 duplicated occurrences of the string literal "integer" throughout the class. This is the foundational change that enables all other hunks to reference a single constant instead of duplicating the literal.java:S1192 - Define a constant instead of duplicating this literal "##default" 3 times. • CRITICAL • View issue
Location:
jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/QNameEnumTypeDefinition.java:56Why is this an issue?
Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.
What changed
Introduces the constant
DEFAULT_MARKERwith value"##default"to replace the duplicated string literal. This is the central definition that all other hunks reference, directly addressing the code smell about duplicating the string literal"##default"3 times.SonarQube Remediation Agent uses AI. Check for mistakes.