Skip to content

SLING-13236 - MapEntries: NPE when resource change is delivered during construction or disposal#210

Open
ciechanowiec wants to merge 4 commits into
apache:masterfrom
ciechanowiec:SLING-13236
Open

SLING-13236 - MapEntries: NPE when resource change is delivered during construction or disposal#210
ciechanowiec wants to merge 4 commits into
apache:masterfrom
ciechanowiec:SLING-13236

Conversation

@ciechanowiec

Copy link
Copy Markdown

Fixes SLING-13236.

…g construction or disposal

The MapEntries constructor registered itself as a ResourceChangeListener
before assigning the VanityPathHandler field, so a change delivered by the
asynchronous "Apache Sling Resource Provider Change Notifier" thread in
that window caused:

  java.lang.NullPointerException: Cannot invoke
  "...VanityPathHandler.isReady()" because "this.vph" is null
    at ...MapEntries.onChange(MapEntries.java:460)

Symmetrically, dispose() tore down the AliasHandler before unregistering
the listener, allowing the equivalent NPE on "this.ah" during shutdown.

Fix: assign the VanityPathHandler before registering the listener (events
arriving before initializeVanityPaths completes are queued and drained by
the initializer, as designed), and unregister the listener first in
dispose(). Add deterministic regression tests for both races.

@joerghoh joerghoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

you might consider the apply the 2 nitpicks; the sling resourceresolver is entirely resource-based and does not know about "nodes" at all.

Comment thread src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Outdated
Comment thread src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Outdated
ciechanowiec and others added 3 commits June 7, 2026 21:07
…apEntriesTest.java

Co-authored-by: Jörg Hoh <joerghoh@users.noreply.github.com>
…apEntriesTest.java

Co-authored-by: Jörg Hoh <joerghoh@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants