spotbugs: fix PZLA, SI, DB_DUP, MC_OVERRIDABLE — 4 small residual findings#7643
Open
Vest wants to merge 1 commit into
Open
spotbugs: fix PZLA, SI, DB_DUP, MC_OVERRIDABLE — 4 small residual findings#7643Vest wants to merge 1 commit into
Vest wants to merge 1 commit into
Conversation
70548a3 to
3544fec
Compare
- Region: reorder static fields so ordinalCount precedes the final NONE constant, and drop the redundant '= 0' initializer. Today the '= 0' assignment runs *after* the NONE constructor reads ordinalCount++, which works only because Java zero-inits ints. If anyone added another public-static Region constant later it would collide with NONE on ordinal 0. Fixes SI_INSTANCE_BEFORE_FINALS_ASSIGNED. - HitPointFacet.rollHP: name HP_STANDARD as its own case (it is the documented primary mode and the default loaded by SettingsHandler), and turn 'default' into an explicit errorPrint-and-fall-back for unknown HP roll methods. Matches the cdom/facet convention for invalid-internal-state (cf. ArmorClassFacet's 'Invalid ACType'). Drops the silent duplication that DB_DUP flagged while preserving the safety net for corrupted config. - FactSetParser.unparse: suppress PZLA_PREFER_ZERO_LENGTH_ARRAYS. null on the error path is deliberate: it distinguishes 'unparse errored' from 'no output' (empty array). Same convention as TemplateFeatToken.unparse. - CDOMObject.clone: suppress MC_OVERRIDABLE_METHOD_CALL_IN_CLONE on the ownBonuses() call. PCClass overrides ownBonuses to recurse into its PCClassLevel children; making it final would break that. The override only reads the clone's BONUS list, which super.clone() already populated. SpotBugs total: 77 -> 71.
3544fec to
fb4a885
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Closes four small SpotBugs findings that no other open PR covers.
SI_INSTANCE_BEFORE_FINALS_ASSIGNEDRegion.java:41= 0DB_DUPLICATE_SWITCH_CLAUSESHitPointFacet.java:94HP_STANDARDexplicitly; makedefaultan explicit warn-and-fall-backPZLA_PREFER_ZERO_LENGTH_ARRAYSFactSetParser.java:137MC_OVERRIDABLE_METHOD_CALL_IN_CLONECDOMObject.java:1061Why each
SI / Region.java —
public static final Region NONE = new Region(...)ran the constructor (which doesordinal = ordinalCount++) before the explicitprivate static int ordinalCount = 0initializer below it. Today it works because Java zero-inits the int, but the explicit= 0re-zeros the counter afterNONE's construction. If anyone added a secondpublic static final Region X = new Region(...)constant later, it would collide on ordinal 0. Real latent bug. Fix: declare the counter/map first, drop the redundant= 0, thenNONE.DB_DUP / HitPointFacet.rollHP — the
HP_STANDARDcase anddefaultcase had identical bodies:The two cases mean different things, though —
HP_STANDARDis the named, documented primary mode (it's the default value loaded bySettingsHandler.getPCGenOption("hpRollMethod", Constants.HP_STANDARD)), anddefaultis the safety net for unknown values (corrupted config). Collapsing them either way loses information. Fix: keepHP_STANDARDas its own named case, and turndefaultinto an explicit warn-and-fall-back so SpotBugs no longer sees a duplicate body:PZLA / FactSetParser.unparse —
return nullis a deliberate sentinel: it distinguishes "this token errored out (already calledaddWriteMessage)" from "this token has no output for this object" (which returnsnew String[0]). The codebase uses this same idiom inTemplateFeatToken.unparseand other parsers. Suppressing with rationale is correct; the alternative would change semantics callers rely on.MC_OVERRIDABLE / CDOMObject.clone — calls
clone.ownBonuses(clone), andownBonusesispublic/overridable.PCClass.ownBonuses(PCClass.java:1418) overrides it to recursively re-own bonuses on itsPCClassLevelchildren — making itfinalwould break that. The override only reads the clone'sBONUSlist, whichsuper.clone()populated before the call, so the "half-cloned" warning doesn't apply in practice. Suppress with rationale.Verification
./gradlew compileJava compileTestJava compileItestJava compileSlowtestJava— clean./gradlew test— all unit tests pass./gradlew clean spotbugsMain— the four target rules each report 0:SI_INSTANCE_BEFORE_FINALS_ASSIGNED: 0DB_DUPLICATE_SWITCH_CLAUSES: 0PZLA_PREFER_ZERO_LENGTH_ARRAYS: 0MC_OVERRIDABLE_METHOD_CALL_IN_CLONE: 0EQ_COMPARETO_USE_OBJECT_EQUALSand oneCT_CONSTRUCTOR_THROWas a side-effect).Files