Skip to content

[Misc] Define constants for duplicated String literals (SonarCloud java:S1192)#5787

Merged
vmassol merged 1 commit into
masterfrom
claude/sleepy-faraday-isocfz
Jul 7, 2026
Merged

[Misc] Define constants for duplicated String literals (SonarCloud java:S1192)#5787
vmassol merged 1 commit into
masterfrom
claude/sleepy-faraday-isocfz

Conversation

@vmassol

@vmassol vmassol commented Jul 7, 2026

Copy link
Copy Markdown
Member

Description

Fixes 21 SonarCloud java:S1192 issues ("Define a constant instead of duplicating this literal N times") by extracting private static final String constants for String literals that were duplicated 3+ times within a single class.

Files changed (issues resolved):

  • MimeTypesUtil — 9 (MIME-type literals repeated across the MIME_TYPES lookup table; constants declared before the static array so they can be referenced from its initializer)
  • FeedPlugin — 6 (XWiki.FeedEntryClass, feedimgurl, updateFeedError, title, author, fullContent)
  • SchedulerPlugin — 4 (jobName, status, Paused, Normal)
  • SchedulerPluginApi — 2 (error, jobName)

No behavior change — only literal-to-constant extraction. Javadoc occurrences of the same words were intentionally left untouched. The three affected Maven modules build cleanly (checkstyle + Spoon pass).

SonarCloud issues (rule java:S1192, project org.xwiki.platform:xwiki-platform):
https://sonarcloud.io/project/issues?resolved=false&rules=java%3AS1192&id=org.xwiki.platform%3Axwiki-platform


Generated by Claude Code

…va:S1192)

Extract private constants for String literals that were duplicated 3+
times within MimeTypesUtil, FeedPlugin, SchedulerPlugin and
SchedulerPluginApi, resolving 21 SonarCloud java:S1192 issues.

Co-Authored-By: Vincent Massol <vincent@massol.net>
@vmassol vmassol added the llm-agent To be used for PRs created autonomously by LLM agents. label Jul 7, 2026 — with Claude
@manuelleduc

Copy link
Copy Markdown
Contributor

I would have expected excludes in maven-checkstyle-plugin plugins in the pom to be updated accordingly.

@vmassol vmassol self-assigned this Jul 7, 2026

vmassol commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Good point — I looked into it. These four files are excluded from Checkstyle entirely (file-level <excludes> in each module's maven-checkstyle-plugin config), so removing them from <excludes> doesn't just re-enable MultipleStringLiterals — it enables the full ruleset. I tried it and the build fails with a large amount of pre-existing legacy debt unrelated to this change, e.g. FeedPlugin alone reports 264 violations: MissingJavadocMethod/JavadocMethod (~86), MultipleStringLiterals at Checkstyle's stricter ≥2 threshold that Sonar's S1192 doesn't flag (18 more, e.g. "date" ×8, "url" ×4, ":" ×7), plus CyclomaticComplexity/NPathComplexity/ExecutableStatementCount/ParameterNumber/DeclarationOrder/EmptyCatchBlock/NestedIfDepth/LineLength. MimeTypesUtil, SchedulerPlugin and SchedulerPluginApi are in the same situation.

So un-excluding them can't be done as part of this S1192-only PR — each would need a full Checkstyle cleanup (Javadoc, complexity refactors, the remaining sub-threshold literals, etc.), which is a substantially larger effort per file. I've kept the <excludes> as-is here. Happy to open a separate follow-up to fully clean up and un-exclude one or more of these files if you think that's worthwhile — just let me know which to prioritise.


Generated by Claude Code

@vmassol vmassol merged commit ea28ab2 into master Jul 7, 2026
3 checks passed
@vmassol vmassol deleted the claude/sleepy-faraday-isocfz branch July 7, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-agent To be used for PRs created autonomously by LLM agents.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants