mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
Fix NPE if there is no resource provider for an URI
Fix NPE if there is no resource provider for an URI by checking for null and defaulting to false if null, the null check is equivalent to the one already present in getDeltasForDeletedResources. In addition mark the URI for removal. The resource provider can be null in our development environments or if a persisted index is being reused after some language was de-installed.
This commit is contained in:
parent
b082274403
commit
81b88c9e54
1 changed files with 35 additions and 13 deletions
|
@ -198,10 +198,18 @@ public class Indexer {
|
|||
.transform(IResourceDescription::getURI).copyInto(new HashSet<>());
|
||||
remainingURIs.removeAll(FluentIterable.from(deltas).transform(Delta::getUri).toSet());
|
||||
List<URI> allAffected = FluentIterable.from(remainingURIs).filter(it -> {
|
||||
IResourceDescription.Manager manager = context.getResourceServiceProvider(it)
|
||||
.getResourceDescriptionManager();
|
||||
IResourceDescription resourceDescription = previousIndex.getResourceDescription(it);
|
||||
return isAffected(resourceDescription, manager, allDeltas, allDeltas, newIndex);
|
||||
IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(it);
|
||||
if (resourceServiceProvider != null) {
|
||||
IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
|
||||
IResourceDescription resourceDescription = previousIndex.getResourceDescription(it);
|
||||
return isAffected(resourceDescription, manager, allDeltas, allDeltas, newIndex);
|
||||
} else {
|
||||
IResourceDescription.Delta delta = getDeltaForDeletedResource(it, previousIndex);
|
||||
if (delta != null) {
|
||||
deltas.add(delta);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}).toList();
|
||||
deltas.addAll(getDeltasForChangedResources(allAffected, previousIndex, context));
|
||||
return new Indexer.IndexResult(deltas, newIndex);
|
||||
|
@ -213,21 +221,35 @@ public class Indexer {
|
|||
protected List<IResourceDescription.Delta> getDeltasForDeletedResources(BuildRequest request,
|
||||
ResourceDescriptionsData oldIndex, BuildContext context) {
|
||||
List<IResourceDescription.Delta> deltas = new ArrayList<>();
|
||||
for (URI deleted : request.getDeletedFiles()) {
|
||||
IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(deleted);
|
||||
if (resourceServiceProvider != null) {
|
||||
operationCanceledManager.checkCanceled(context.getCancelIndicator());
|
||||
IResourceDescription oldDescription = oldIndex != null ? oldIndex.getResourceDescription(deleted)
|
||||
: null;
|
||||
if (oldDescription != null) {
|
||||
DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(oldDescription, null);
|
||||
deltas.add(delta);
|
||||
if (oldIndex != null) {
|
||||
for (URI deleted : request.getDeletedFiles()) {
|
||||
IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(deleted);
|
||||
if (resourceServiceProvider != null) {
|
||||
operationCanceledManager.checkCanceled(context.getCancelIndicator());
|
||||
IResourceDescription.Delta delta = getDeltaForDeletedResource(deleted, oldIndex);
|
||||
if (delta != null) {
|
||||
deltas.add(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return deltas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a delta for a resource that shall be deleted.
|
||||
*
|
||||
* @since 2.26
|
||||
*
|
||||
*/
|
||||
protected IResourceDescription.Delta getDeltaForDeletedResource(URI uri, ResourceDescriptionsData oldIndex) {
|
||||
IResourceDescription oldDescription = oldIndex.getResourceDescription(uri);
|
||||
if (oldDescription != null) {
|
||||
return new DefaultResourceDescriptionDelta(oldDescription, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the changed resources.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue