eclipse-xtext / eclipse-xtext/xtext

NPE possible in org.eclipse.xtext.resource.containers.StateBasedContainerManager#internalGetContainerHandle

Open
#2,744 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

https://github.com/eclipse/xtext/blob/9c7e544166dfcf10790eedeaa5c15dc490cb66fc/org.eclipse.xtext/src/org/eclipse/xtext/resource/containers/StateBasedContainerManager.java#L116C1-L118C3

internalGetContainerHandle assumes desc is always nonNull. I have a case where that isn't true (not certain why - I'm still debugging that). If that assumption is deliberate, I suggest adding a comment documenting the assumption and/or adding a throws statement so users know what to expect. If it isn't deliberate, I suggest adding a null pointer check somewhere.

My particular error comes in the middle of code I modified from Lorenzo Bettini's Xtext/XTend book (2nd Edition) - in the SmallJava examaple. Specifically this code:

      @Inject ResourceDescriptionsProvider rdp
      @Inject IContainer.Manager cm

       ....

	def getVisibleContainers(EObject o) {
		val index = rdp.getResourceDescriptions(o.eResource)
		val rd = index.getResourceDescription(o.eResource.URI)
		cm.getVisibleContainers(rd, index)
	}

Apparently the value of rd is null - thus causing the NPE when it gets into internalGetContainerHandle inside the getVisibleContainers call.

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 in org.eclipse.xtext/src/org/eclipse/xtext/resource/containers/StateBasedContainerManager.java at internalGetContainerHandle and inspect how getVisibleContainers passes its resource description. Reproduce the supplied SmallJava example, where getResourceDescription may return null, and determine the intended null contract. Done means the behavior is documented or safely handled with a regression test for the reported path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.