Repository navigation
Fix NPE from a listener-registration race in the Attributes panel - #3232
Merged
Merged
Conversation
The constructor registered "this" as a listener on the shared AttributesUIControllerImpl before columnsButton (and cardLayout/cardPanel) were assigned. AttributesUIControllerImpl's workspace-selection listener fires firePropertyChangeEvent() synchronously on whatever thread selects the workspace, so it can reach setup()/unsetup() while the EDT is still mid-construction, NPEing on columnsButton.setEnabled(...). Move the listener registration to the end of the constructor so no event is delivered before all fields are assigned, and add a defensive null check in setup()/unsetup() in case of any similar future ordering issue. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
listeners was a plain HashSet mutated/iterated without synchronization, and select()/unselect() fired property change events directly instead of going through the EDT-confining runAction() used everywhere else in the class. Switch to CopyOnWriteArraySet and route select/unselect through runAction for consistency and defense in depth against the construction-time race fixed in cecb363. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Aug 23, 2026
pull Bot
pushed a commit
to admariner/gephi
that referenced
this pull request
Aug 26, 2026
…p 3) Same bug class as PR gephi#3232 (commit cecb363): a controller registers a WorkspaceListener/PropertyChangeListener early in its constructor, so events can be delivered on another thread while the rest of the constructor is still running. - AppearanceUIController (finding 3): pc.addWorkspaceListener(...) used to be registered before "listeners"/"transformers" were assigned, and before the constructor's own bootstrap block (which independently populates "model" for an already-selected workspace) had finished. Moved registration to the last statement of the constructor. This closes both the original NPE-on-"listeners" window and the model-duplication race an earlier adversarial review pass found in the bootstrap block (select()/unselect()/disable() write "model" synchronously, with no invokeLater deferral, so preventing the listener from firing during construction is the only way to close that race). - PreviewUIControllerImpl / its three second-layer listeners (finding 4): audited all three consumers rather than trusting the pre-gephi#3255 issue text, per the plan's own instruction. - PreviewUIControllerImpl itself needed no change (listeners is inline-initialized at field declaration; no NPE window exists). - PreviewTopComponent: propertyChange()'s SELECT branch wrote the "model" field and called initTarget() (many raw Swing mutations) directly and unguarded, reachable off-EDT since gephi#3255. Deferred both together into one invokeLater. - RendererManager: propertyChange() called setup() with *no* guarding at all -- a raw panel rebuild (removeAll/add/updateUI) on every workspace select/unselect, off the EDT. Wrapped in invokeLater. - PreviewSettingsTopComponent needed no further change; its Swing work was already deferred by an earlier fix. "Register last" was tried for these three second-layer listeners too, matching AppearanceUIController's shape, but reverted after adversarial review: once a listener's own Swing work is deferred via invokeLater, the corruption risk that reordering prevents is already closed, and registering later only adds a new downside -- an event landing in the gap between the constructor's bootstrap read and the (now later) registration is silently dropped rather than self-corrected by the listener's own deferred runnable once construction finishes. Unlike AppearanceUIController, none of these three write off-EDT synchronously, so there was no corruption bug for reordering to fix in the first place. Refs gephi#3246. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Description
Users open (or restore) the Attributes panel and hit a NullPointerException before the window ever renders (63 users / 90 events on Sentry).
AttributesTopComponent's constructor registeredthisas aPropertyChangeListeneron the sharedAttributesUIControllerImplsingleton (controller.addPropertyChangeListener(this)) before the constructor had finished assigning its own fields, in particularcolumnsButton,cardLayout, andcardPanela few lines later.AttributesUIControllerImpl's internalWorkspaceListener.select(Workspace)callsfirePropertyChangeEvent(...)directly (not marshalled throughSwingUtilities.invokeLater), and it iterates a plain, unsynchronizedHashSet<AttributesUIModelListener>. BecauseProjectControllercan select a workspace from a non-EDT thread (e.g. during project loading), that call can land onAttributesTopComponent.propertyChange(...)->setup(...)while the constructor is still running on the EDT, in the window between the listener registration and thecolumnsButton/cardLayout/cardPanelassignments.setup()then callscolumnsButton.setEnabled(true)on a field that is stillnull, producing the NPE.Fix: register the listener at the very end of the constructor, after every field it can indirectly touch (via
setup()/unsetup()) has been assigned, so no event can be delivered mid-construction. As defense in depth (since the controller's listener set is shared/unsynchronized and could see similar ordering issues from future changes),setup()/unsetup()now bail out early ifcardLayout,cardPanel, orcolumnsButtonaren't set yet, instead of assuming they always are.https://gephi.sentry.io/issues/GEPHI-5TR
Checklist
Added tests?
This module (
DesktopAttributes) has no existing unit test setup, and the bug is a cross-thread timing race in construction of a NetBeansTopComponenttied toWindowManager/ProjectController/Lookupsingletons — not something that can be reproduced deterministically in a unit test without a full platform test harness. The fix removes the race window entirely (registration only happens after full construction) plus a defensive null-check, so the failure mode this addresses can no longer occur regardless.Added to documentation?