Skip to content

NPE when calling Event.getProperty() - Race of two concurrent events with the same topic #4250

Description

@Cewin-91
  • I verified I can reproduce this issue against 2026-06

Problem

!MESSAGE java.lang.NullPointerException: Cannot invoke
"org.osgi.service.event.Event.getProperty(String)" because "event" is null

org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException: ...
Caused by: java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.addons.perspectiveswitcher.PerspectiveSwitcher.handleLabelEvent(PerspectiveSwitcher.java:197)

EventObjectSupplier.get(...) reads its currentEvents map (keyed by topic only) via an unsynchronized check-then-act:

if (!currentEvents.containsKey(topic)) {
    return IInjector.NOT_A_VALUE;
}
return currentEvents.get(topic).getProperty(DATA);   // entry may have been removed meanwhile -> NPE

Steps to reproduce

DIEventHandler.handleEvent adds/removes that entry non-atomically around every delivery, so two concurrent deliveries on the same topic race. The attached JUnit test drives the production EventObjectSupplier directly (no OSGi, no injector) — one thread repeatedly does addCurrentEvent/removeCurrentEvent, the main thread repeatedly calls get(...) for a non-Event parameter type, which hits the branch that dereferences the (possibly just-removed) map entry:
EventObjectSupplierRaceTest.java

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions