eclipse-xtext / eclipse-xtext/xtext

Can't access Activator/BundleContext during shared service initialization

Open
#2,453 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help_wanted
Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Steps to reproduce:

  1. create a service (Java class) that accesses something like Activator.getDefault().getBundle().getBundleContext().getServiceReference(SomeService.class) in the constructor.
  2. bind the service in a custom shared state module that has been registered via Xtext's extension point.
  3. Starting org.eclipse.xtext.ui.shared will now fail.

Analysis: the code from (1) throws an NPE because it's called during org.eclipse.xtext.ui.shared.internal.Activator.start(BundleContext)

Since the bundle can't be activated users see tons of subsequent ClassNotFoundExceptions because classes from that bundle can't be accessed.

While I don't think the code from (1) needs to be supported in any case... I can say that this used to work because the Shared Injector used to be initialized lazily and thus after bundle startup finished.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with org.eclipse.xtext.ui.shared.internal.Activator.start(BundleContext) and trace how the custom shared state module is initialized through Xtext's extension point. Reproduce the constructor access to Activator.getDefault().getBundle().getBundleContext() and determine the initialization ordering that causes the NPE. Done means org.eclipse.xtext.ui.shared starts successfully without the subsequent ClassNotFoundExceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.