Skip to content

Fix NPE from a listener-registration race in the Attributes panel - #3232

Merged
mbastian merged 2 commits into
masterfrom
fix/attributes-panel-init-race
Aug 23, 2026
Merged

mbastian merged 2 commits into
masterfrom
fix/attributes-panel-init-race

Conversation

@mbastian

Copy link
Copy Markdown
Member

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 registered this as a PropertyChangeListener on the shared AttributesUIControllerImpl singleton (controller.addPropertyChangeListener(this)) before the constructor had finished assigning its own fields, in particular columnsButton, cardLayout, and cardPanel a few lines later.

AttributesUIControllerImpl's internal WorkspaceListener.select(Workspace) calls firePropertyChangeEvent(...) directly (not marshalled through SwingUtilities.invokeLater), and it iterates a plain, unsynchronized HashSet<AttributesUIModelListener>. Because ProjectController can select a workspace from a non-EDT thread (e.g. during project loading), that call can land on AttributesTopComponent.propertyChange(...) -> setup(...) while the constructor is still running on the EDT, in the window between the listener registration and the columnsButton/cardLayout/cardPanel assignments. setup() then calls columnsButton.setEnabled(true) on a field that is still null, 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 if cardLayout, cardPanel, or columnsButton aren't set yet, instead of assuming they always are.

https://gephi.sentry.io/issues/GEPHI-5TR

Checklist

  • Merged with master beforehand

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed

This module (DesktopAttributes) has no existing unit test setup, and the bug is a cross-thread timing race in construction of a NetBeans TopComponent tied to WindowManager/ProjectController/Lookup singletons — 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?

  • 👍 README.md
  • 👍 API Changes
  • 👍 Additional documentation in docs
  • 👍 Relevant code documentation
  • 🙅 no, because they aren't needed

mbastian and others added 2 commits August 22, 2026 19:14
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>
@mbastian mbastian added the UI label Aug 23, 2026
@mbastian mbastian added this to the 0.11.3 milestone Aug 23, 2026
@mbastian
mbastian merged commit 4893637 into master Aug 23, 2026
1 check passed
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>
@mbastian
mbastian deleted the fix/attributes-panel-init-race branch November 17, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant