Skip to content

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

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

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

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 in the AsciiDoctorTemplateResolver.java file, specifically due to the repeated use of the literal string "classpath:/" four times. This issue is considered critical because it indicates a duplication of effort, making the code harder to maintain and understand.

In essence, when the same value appears multiple times in the code, it can lead to:

  • Increased maintenance overhead
  • Difficulty in understanding the intent behind the repeated values
  • Potential for errors if the value needs to be updated

By defining a constant instead of duplicating the literal string, we can make the code more maintainable and easier to understand.

Fix

To fix this issue, we can define a constant at the top of the file:

private static final String CLASSPATH_PREFIX = "classpath:/";

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

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

// After
String templatePath = CLASSPATH_PREFIX + "...";

Caveats and Edge Cases

When applying this fix, keep in mind:

  • Make sure to update all occurrences of the repeated literal string to use the new constant.
  • If the value is not a simple string, consider using an enum or a configuration file instead of a constant.
  • Be cautious when defining constants, as they can make the code harder to understand if not used judiciously.

By addressing this critical code smell, we can improve the maintainability and readability of our codebase.


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