Skip to content

Fix switch case fall-through and eliminate duplicated string literals#23

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260615-010145-05db67d2
Open

Fix switch case fall-through and eliminate duplicated string literals#23
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260615-010145-05db67d2

Conversation

@sonarqube-agent

Copy link
Copy Markdown

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

Why these issues? Selected for their BLOCKER and CRITICAL severity with well-defined, mechanical fixes. The switch case fall-through (S128) is a functional bug with an unconditional remedy, while the string literal duplications (S1192) and class naming (S2176) violations follow automated refactoring patterns with high-confidence outcomes suitable for immediate review.

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. • BLOCKERView issue

Location: core/src/main/java/com/webcohesion/enunciate/api/datatype/BaseType.java:51

Why 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 the case 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.

--- a/core/src/main/java/com/webcohesion/enunciate/api/datatype/BaseType.java
+++ b/core/src/main/java/com/webcohesion/enunciate/api/datatype/BaseType.java
@@ -55,0 +56,1 @@ public enum BaseType {
+        return BaseType.object;
java:S1192 - Define a constant instead of duplicating this literal "String" 20 times. • CRITICALView issue

Location: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java:68

Why 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.

--- a/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java
+++ b/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java
@@ -18,6 +17,0 @@ package com.webcohesion.enunciate.modules.php_xml_client;
-import com.webcohesion.enunciate.api.datatype.DataTypeReference;
-import com.webcohesion.enunciate.api.resources.Entity;
-import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
-import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator;
-import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror;
-import com.webcohesion.enunciate.metadata.ClientName;
java:S2176 - Rename this class. • CRITICALView issue

Location: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java:57

Why 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.

--- a/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java
+++ b/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java
@@ -18,6 +17,0 @@ package com.webcohesion.enunciate.modules.php_xml_client;
-import com.webcohesion.enunciate.api.datatype.DataTypeReference;
-import com.webcohesion.enunciate.api.resources.Entity;
-import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
-import com.webcohesion.enunciate.javac.decorations.TypeMirrorDecorator;
-import com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror;
-import com.webcohesion.enunciate.metadata.ClientName;
java:S1192 - Define a constant instead of duplicating this literal "integer" 12 times. • CRITICALView issue

Location: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java:58

Why 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_TYPE with 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.

--- a/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java
+++ b/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java
@@ -48,0 +49,2 @@ public class TypeNameForMethod extends com.webcohesion.enunciate.util.freemarker
+  private static final String INTEGER_TYPE = "integer";
+
java:S1192 - Define a constant instead of duplicating this literal "##default" 3 times. • CRITICALView issue

Location: jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/QNameEnumTypeDefinition.java:56

Why 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_MARKER with 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.

--- a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/QNameEnumTypeDefinition.java
+++ b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/QNameEnumTypeDefinition.java
@@ -40,0 +41,2 @@ public class QNameEnumTypeDefinition extends EnumTypeDefinition {
+  private static final String DEFAULT_MARKER = "##default";
+

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


SonarQube Remediation Agent uses AI. Check for mistakes.

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-agent

Copy link
Copy Markdown
Author

⚠️ This repository does not have a CODEOWNERS file. The PR has been created but has not been automatically assigned to any reviewer. To ensure PRs are reviewed promptly, consider adding a CODEOWNERS file to your repository.

@sonarqubecloud

sonarqubecloud Bot commented Jun 15, 2026

Copy link
Copy Markdown

SonarQube reviewer guide

Review in SonarQube

Summary: Refactor PHP XML client type conversion logic, extract magic strings to constants, and fix a control flow issue in BaseType type detection.

Review Focus:

  • The new PhpClientClassnameForMethod class contains the original conversion logic extracted from ClientClassnameForMethod. Ensure the refactoring is complete and no logic was inadvertently altered.
  • The BaseType.java change adds an unreachable return statement that needs clarification—verify if this is intentional or addresses a bug in type detection.
  • String constants ("##default", type names) are now extracted to avoid duplication and improve maintainability.

Start review at: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/PhpClientClassnameForMethod.java. This is the new primary implementation file where the majority of logic now resides. The original ClientClassnameForMethod is deprecated in favor of this, so verifying correctness here is critical before accepting the refactoring.

💬 Please send your feedback

Quality Gate Failed Quality Gate failed

Failed conditions
9.9% Duplication on New Code (required ≤ 3%)

🛠️ Remediation Agent ready

  • Fix automatically
    Creates a separate PR with fixes for eligible issues

See analysis details on SonarQube Cloud

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