eclipse-xtext / eclipse-xtext/xtext

NPE in ResourceSetGlobalScopeProvider if no ResourceDescription for a Resource

Open
#2,548 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm working with a ResourceSet that may contain non-Xtext resources.

ResourceSetGlobalScopeProvider.createScopeWithQualifiedNames() cannot handle that (NPE in line 71):

ISelectable compound = new ISelectable() {
	
	@Override
	public boolean isEmpty() {
		for (ISelectable description: resourceDescriptions) {
			// NPE for description
			if (!description.isEmpty())
				return false;
		}
		return true;
	}

Proposed fix: Add a nonNull filter to the resourceDescriptions iterator:

final Iterable<ISelectable> resourceDescriptions = Iterables.filter(
		Iterables.transform(resourceSet.getResources(),
				from -> this.resourceDecriptionProvider.getResourceDescription(from)),
		Objects::nonNull);

And when we're at it, converting the anonymous ISelectable within createScopeWithQualifiedNames() into a real class would support subclassing a lot.

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 at ResourceSetGlobalScopeProvider.createScopeWithQualifiedNames(), using a ResourceSet containing a non-Xtext resource to reproduce the null ResourceDescription failure. Ensure resources without descriptions no longer cause an NPE, and consider whether the anonymous ISelectable should become subclassable as proposed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.