[Misc] Fix various SonarQube issues in oldcore, livedata and the group cache - #6325
Merged
Conversation
…p cache * java:S3398 (2): move a private helper into the nested class that is its only user (AbstractGroupCache.GroupCacheEntry and R72000Work). * java:S5663 (1): replace a single-line text block with a string literal. * java:S1450 (1): StatsUtil's cookieExpirationDate static field is written and read by one method only, so it becomes a local. Co-Authored-By: Vincent Massol <vincent@massol.net> Claude-Session: https://claude.ai/code/session_01FTH7nnTgyrquQ4VFuesFYG
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
Four SonarCloud issues, all mechanical and all verified by the compiler plus the modules' own test
suites.
java:S3398private methods called only by inner classes should be moved to those classesjava:S5663use a simple literal for a single-line stringLiveDataRenderer's one-line text block becomes a string literal.java:S1450field should be a local variableStatsUtil.cookieExpirationDateis written and read by one method only.Per site:
AbstractGroupCache#addToIndex(String, Collection)→GroupCacheEntry#addToIndex(Collection). Bothcall sites already passed
this.key, so the parameter disappears. The singularaddToIndex(String, DocumentReference)overload stays on the outer class becausegetCacheEntry(...)still calls it; since the inner class now declares a method of that name, thecall to the outer overload is written
AbstractGroupCache.this.addToIndex(...).R72000XWIKI12153DataMigration#convert→R72000Work, together with its only calleeaddBatch. Movingconvertalone would have leftaddBatchcalled only from the inner class,which just relocates the same issue onto it;
addBatchreads one outer field, nowR72000XWIKI12153DataMigration.this.serializer.LiveDataRenderer: the text block has a single content line, so incidental-indentation strippingmakes it exactly the literal. Verified with a throwaway program rather than by eye —
old.equals(new)printstrueand the value is<script type='application/json' data-config-content-trusted="%s"></script>.StatsUtil#getCookieExpirationDate()assigned aprivate static Datefield and immediatelyreturned it. Nothing else reads the field, so it is gone and the method returns
cal.getTime()directly — which also removes a mutable static from a
finalutility class.Clarifications
Four of the six platform
java:S3398sites were deliberately left open, because the rule'sremediation would cost more than the issue:
UsedValuesListQueryBuilder#canView→ViewableValueFilter: the body mentions seven types andfour injected components, so the move raises the target class's Checkstyle
ClassFanOutComplexity.DocumentTranslationBundleFactory#translationDocumentUpdated→ the anonymousEventListener: itreads three outer members, and the target is a field initializer, so the move would bury a
15-line method inside a field declaration.
FilesystemAttachmentStore#resolveAttachmentVersioningStore→AttachmentSaveTransactionRunnable:applied, then reverted. Its only callee
getAttachmentVersioningStorehas no other caller, so themove raises a fresh
java:S3398on the callee, and moving that one in as well dragscomponentManager,loggerandComponentLookupExceptioninto the runnable. Clearing one issueby creating another is not worth it.
AbstractMimeMessageIterator#onPrepare→ the anonymousVoidMailListener: applied, then revertedbecause
checkstyle:checkrejected it —AnonInnerLength: Anonymous inner class length is 26 lines (max allowed is 20). The listener isalready 20 lines, so it cannot host the method the rule wants moved into it. The file is
byte-identical to
masteragain.java:S1172,java:S1117,java:S6355andjava:S1123were all checked for shippable sites in thesame pass and had none left (respectively: no
privatesite remains; the 13 open sites are in twofiles an open pull request already touches; and the remaining
@Deprecated/Javadoc-tag sites do notstate a deprecating version anywhere in the source, so filling one in would mean inventing it).
No other open issue in this repo sits on a line this PR rewrites — checked per changed file against
the project's open-issue list before pushing.
Screenshots & Video
N/A
Executed Tests
Reactor of 12 modules, tests on,
-Plegacy,quality(so Revapi, Checkstyle, Spoon and JaCoCo allran). 1925 tests green, per module:
xwiki-platform-legacy-oldcoreis in the list on purpose:AspectJinter-type declarations can callan oldcore class's
privatemembers from that module, which no other compiler sees. It built green(48/48) and
revapi:checkreported API checks completed without failures.The only red module in that reactor was
xwiki-platform-notifications-notifiers-default, on theAnonInnerLengthviolation described under Clarifications; that file has since been reverted tomastercontent and is no longer part of this pull request.Expected merging strategy
Squash and merge; no backport needed.
Generated by Claude Code