Skip to content

fix: Define a constant instead of duplicating this literal "classpath:/" 4 ti#3

Open
ciadoh wants to merge 1 commit into
mainfrom
sonar-fix/a19cb449-33a4-47ee-88c1-7d8c610db92d-1782126373
Open

fix: Define a constant instead of duplicating this literal "classpath:/" 4 ti#3
ciadoh wants to merge 1 commit into
mainfrom
sonar-fix/a19cb449-33a4-47ee-88c1-7d8c610db92d-1782126373

Conversation

@ciadoh

@ciadoh ciadoh commented Jun 22, 2026

Copy link
Copy Markdown
Owner

SonarQube Issue

Key: a19cb449-33a4-47ee-88c1-7d8c610db92d
File: src/main/java/org/owasp/webgoat/container/AsciiDoctorTemplateResolver.java

AI Analysis & Fix

Issue Explanation:

The SonarQube tool has flagged a Critical Code Smell issue in the AsciiDoctorTemplateResolver.java file. The issue is that the string literal "classpath:" is duplicated four times in the code, which can lead to maintenance issues if the value needs to be changed in the future.

Defining a constant instead of duplicating literals improves code readability and maintainability by making it easier to update values throughout the codebase.

Fix:

To fix this issue, we can define a constant for the classpath value:

public static final String CLASSPATH = "classpath:/";

Then, replace all occurrences of the duplicated literal with the new constant:

// Before
String templatePath = "classpath:/";

// After
String templatePath = getClasspath();

Code Example:

public class AsciiDoctorTemplateResolver {
    public static final String CLASSPATH = "classpath:/";
    
    // ...
}

In this example, we define a constant CLASSPATH and use it instead of duplicating the literal value.

Caveats and Edge Cases:

  • Make sure to update all occurrences of the duplicated literal in the codebase.
  • If the classpath value is not a simple string, consider using a configuration file or environment variable to avoid hardcoding values.
  • This fix assumes that the classpath value does not need to be dynamic. If it does, consider using a more robust solution, such as a properties file or a configuration service.

By applying this fix, we improve code maintainability and reduce the risk of introducing errors due to duplicated literals.


Generated by TechDebt AI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant