spotbugs_ignore: suppress SE_BAD_FIELD for cdom facet events#7632
Open
Vest wants to merge 1 commit into
Open
Conversation
All 10 SE_BAD_FIELD findings are on EventObject subtypes in pcgen.cdom.*:
- pcgen.cdom.facet.CategorizedDataFacetChangeEvent #category
- pcgen.cdom.facet.SkillRankFacet$SkillRankChangeEvent #charID
- pcgen.cdom.facet.analysis.LevelFacet$LevelChangeEvent #charID
- pcgen.cdom.facet.event.SubScopeFacetChangeEvent #charID
- pcgen.cdom.facet.model.ClassFacet$ClassLevelChangeEvent #charID
- pcgen.cdom.facet.model.ClassFacet$ClassLevelObjectChangeEvent
#charID, #newLvl, #oldLvl
- pcgen.cdom.formula.VariableChangeEvent #varID
- pcgen.cdom.reference.UnconstructedEvent #reference
These classes extend java.util.EventObject, which carries the
Serializable marker. The flagged fields (CharID, VariableID, Skill,
PCClassLevel, references) hold runtime identifiers that would be
meaningless after deserialization on a different JVM run.
Verified: zero ObjectOutputStream/writeObject references anywhere in
the codebase. The Serializable contract is inherited from EventObject,
not exercised by pcgen. Marking each field 'transient' would be 10
field annotations + serialVersionUIDs of ceremony for a code path that
never runs.
Same shape as the existing SE_NO_SERIALVERSIONID suppression (line 24,
'not relevant to pcgen') and consistent with the EI_EXPOSE_REP rule
added in PR PCGen#7625 - the cdom layer is wired by shared reference, not
by value-copy.
The scope is narrowed to facet/formula/reference subpackages of
pcgen.cdom rather than all of pcgen.cdom.*; a survey confirmed no
non-event Serializable classes exist in these packages today, and if
one is added in future the narrower scope makes it easier to spot.
Drops spotbugs findings from 77 -> 67.
Contributor
Author
|
We have decided not to use |
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.
All 10
SE_BAD_FIELDfindings underpcgen.cdom.*are onEventObjectsubtypes — facet change events that inheritSerializablefromjava.util.EventObjectbut hold runtime-only identifiers (CharID,VariableID,Skill,PCClassLevel, references to mutable domain objects). TheSerializablecontract is inherited fromEventObject, not exercised by pcgen —grep -r ObjectOutputStream\|writeObject code/src/javareturns nothing.Affected classes
pcgen.cdom.facet.CategorizedDataFacetChangeEventcategorypcgen.cdom.facet.SkillRankFacet$SkillRankChangeEventcharIDpcgen.cdom.facet.analysis.LevelFacet$LevelChangeEventcharIDpcgen.cdom.facet.event.SubScopeFacetChangeEventcharIDpcgen.cdom.facet.model.ClassFacet$ClassLevelChangeEventcharIDpcgen.cdom.facet.model.ClassFacet$ClassLevelObjectChangeEventcharID,newLvl,oldLvlpcgen.cdom.formula.VariableChangeEventvarIDpcgen.cdom.reference.UnconstructedEventreferenceWhy suppress rather than mark
transientMarking each non-
Serializablefieldtransient(Option A in the analysis) would be 10 field annotations + addingserialVersionUIDto each class — ceremony for a code path that never executes. The field types (CharIDetc.) are runtime identifiers whose values would be meaningless after deserialization onto a different JVM run anyway, sotransientwould be the correct annotation if anyone ever did try to serialize an event, but the practical result is the same as suppressing: the field doesn't make the journey.Dropping
Serializableentirely (Option B — replacingEventObjectwith a project-local non-Serializableevent base) is more architecturally honest but costs ~50–80 LOC and a project-local convention where the JDK already has one (EventObjectis the event-object idiom in Java). Net result is the same 10 findings cleared.Why not just fix it
Same shape as PR #7625 (EI_EXPOSE_REP) and PR #7626 (IMPROPER_UNICODE): the SpotBugs rule is technically correct, but it does not apply to PCGen's design. The events are deliberately runtime-only, inheriting
Serializableaccidentally fromEventObject. The honest answer is "the contract is inherited, not used" — captured in the XML comment.Filter rule
Scope is narrowed to facet/formula/reference subpackages rather than blanket
pcgen.cdom.*. A survey confirmed zero non-eventSerializableclasses exist in these packages today; if one is added in future the narrower scope makes it easier to spot.This mirrors the existing
SE_NO_SERIALVERSIONIDsuppression atspotbugs_ignore.xml:24("not relevant to pcgen"), which is the same family of decision.SpotBugs delta
Verification
./gradlew spotbugsMain— 10 SE_BAD_FIELD findings cleared, 0 new findings introduced../gradlew :test --tests "pcgen.cdom.facet.*"— clean (filter-only change, no source modifications).Scope note
Standalone — independent of the still-open #7627 (mark CDOM classes final), #7631 (concurrency hygiene), and the merged #7624–#7628. Branched off fresh
origin/master.