[Misc] Record the deliberate SonarQube name-shadowing false positives in the code - #1974
Open
claude[bot] wants to merge 1 commit into
Open
claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
… in the code * Suppress the java:S2176 and java:S9149 issues raised on types and static methods that carry the name of the type or method they specialise on purpose, with a comment stating why in each case. * 63 SonarQube issues. Co-Authored-By: Vincent Massol <vincent@massol.net> Claude-Session: https://claude.ai/code/session_01Y7umCMMQKjGDPL6sojVLdG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira URL
None — this is a
[Misc]SonarQube cleanup commit.Changes
Description
Records, in the code, the deliberate name shadowing that SonarQube reports as
java:S2176("Class names should not shadow interfaces or superclasses") and
java:S9149("Static methods should not hide methods from superclasses").
63 issues over 21 classes, and the diff is insert-only: three lines above a type
declaration, never a change to an existing line. No behaviour can change.
Both rules ask for a rename. In every one of these 21 cases the shared name is the point of the
class — so the remediation the message suggests is either a published-API break or would defeat the
class's only purpose. The resolution the SonarQube guidelines prescribe for that is
@SuppressWarnings("<rule key>")plus a comment saying why, in the code; SonarCloud then closes theissue at the next analysis because the rule stops being raised. The idiom is already established
here —
mastercarries 26@SuppressWarnings("java:S…")in xwiki-commons today.The 63 issues are 4 distinct arguments and 21 classes, so what a reviewer has to check is four
sentences and which group each class belongs to. Note the count is dominated by a single class:
StringToolalone carries 42 of the 63, cleared by one annotation.A — a deprecated class kept only to preserve the old name (9 issues)
It extends the class that replaced it, under the name it is replacing. Renaming it removes the
backward compatibility it exists for. All nine carry an
@deprecatedtag naming that replacement.o.x.extension.wrap.AbstractWrappingObjecto.x.script.wrap.AbstractWrappingObjecto.x.job.internal.AbstractJobStatuso.x.job.AbstractJobStatuso.x.job.internal.AbstractJobo.x.job.AbstractJobo.x.velocity.introspection.AbstractChainableUberspectororg.apache.velocity.util.introspection.AbstractChainableUberspectoro.x.velocity.introspection.ChainableUberspectororg.apache.velocity.util.introspection.ChainableUberspectoro.x.velocity.introspection.DeprecatedCheckUberspectororg.apache.velocity.util.introspection.DeprecatedCheckUberspectoro.x.logging.TranslationMarkero.x.logging.marker.TranslationMarkero.x.extension.repository.xwiki.Resourceso.x.repository.Resourceso.x.extension.repository.xwiki.UriBuildero.x.repository.UriBuilderB — a drop-in extension of a third-party type (9 issues)
The type adds behaviour to a library type and keeps its name so that it can stand in for it — for
the Velocity tools and the XStream converters, literally, since they are registered in the library's
place. Each one says so in its own Javadoc.
o.x.text.StringUtilsorg.apache.commons.lang3.StringUtilso.x.velocity.tools.CollectionToolorg.apache.velocity.tools.generic.CollectionToolo.x.velocity.tools.ComparisonDateToolorg.apache.velocity.tools.generic.ComparisonDateToolo.x.velocity.tools.EscapeToolorg.apache.velocity.tools.generic.EscapeToolo.x.filter.xml.internal.parameter.CollectionConvertercom.thoughtworks.xstream.…CollectionConvertero.x.filter.xml.internal.parameter.MapConvertercom.thoughtworks.xstream.…MapConvertero.x.groovy.internal.GroovyScriptEngineFactoryorg.codehaus.groovy.jsr223.GroovyScriptEngineFactoryo.x.logging.Loggerorg.slf4j.Loggero.x.xml.EntityResolverorg.xml.sax.EntityResolvero.x.text.StringUtils's Javadoc is explicit about why the name is shared: "the reason we'reextending Commons Lang instead of creating a separate class is because we're using this class as a
Velocity tool and we want to offer a single binding to users".
C — a static that deliberately hides the inherited one (43 issues)
o.x.velocity.tools.StringToolStringUtilshelperso.x.logging.internal.tail.XStreamFileLoggerTailexist(Path)StringTool's Javadoc states the purpose outright: "basicallyorg.apache.commons.lang3.StringUtilsbut with fewer deprecated methods, to control the deprecation in XWiki and to keep methods available
in Velocity whose recommended alternative isn't available in Velocity". Re-declaring the inherited
statics is that mechanism, and the method names are the
$stringtoolscripting API, so theycannot be renamed either.
D — a test fixture whose hiding is the thing under test (2 issues)
DefaultVelocityManagerTest.SubTestClassdeclaresoverwrittenStaticMethod()andoverwrittenDeprecatedStaticMethod()hidingTestClass's, because the tests below check how theuberspector resolves exactly that.
Clarifications
@SuppressWarningswas added where I could not state a reason. That is what keeps the restcredible; nothing here was suppressed merely to clear a count.
SonarCloud Code Analysisapp check may still report a pre-existing finding in one of the 21changed files, because the app's project gate counts every issue in a changed file rather than
the issues the PR's own lines carry.
Quality / Analyze— which is this repo's verdict — cannotfire on this PR at all: the diff writes no existing line, it only inserts above declarations.
Related
Same sweep, same two rules, in the sibling repos:
Screenshots & Video
N/A
Executed Tests
BUILD SUCCESS, 960 tests green in 5:38 over 12 modules (xwiki-commons-extension-api,xwiki-commons-filter-xml,xwiki-commons-groovy,xwiki-commons-job-api,xwiki-commons-job-default,xwiki-commons-legacy-velocity,xwiki-commons-logging-api,xwiki-commons-logging-common,xwiki-commons-repository-api,xwiki-commons-text,xwiki-commons-velocity,xwiki-commons-xml).checkstyle:checkandrevapi:checkran and passedin all of them.
Expected merging strategy
Squash and merge,
masteronly — no backport needed.Generated by Claude Code