eclipse-xtext / eclipse-xtext/xtext
Sporadically thrown NPE and NSEE during issue processing after validation.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
Hello,
during the ValidationJob execution there is sometimes a NPE or NSE (NoSuchElementException) thrown. (Running with Xtext 2.38.0 on Eclipse 4.35)
The following Stacktraces are happening sometimes. Its not easily reproduceable and they are happening sporadically, so we have to try to understand whats the root cause of it.
java.lang.NullPointerException: Cannot invoke "org.eclipse.jface.text.source.IAnnotationModel.getAnnotationIterator()" because the return value of "java.util.Map.get(Object)" is null at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:758) at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:682) at org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor.getAnnotationsToRemove(AnnotationIssueProcessor.java:109) at org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor.processIssues(AnnotationIssueProcessor.java:73) at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:79) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
java.util.NoSuchElementException at java.base/java.util.concurrent.ConcurrentHashMap$KeyIterator.next(ConcurrentHashMap.java:3460) at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:758) at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:682) at org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor.getAnnotationsToRemove(AnnotationIssueProcessor.java:109) at org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor.processIssues(AnnotationIssueProcessor.java:73) at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:79) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
The testcase in which the exceptions above are thrown is testing simple editing in our DSL editor (adding and removing characters), which might cause validation issues or the Collapse/Expand buttons which are added to the AnnotationModel etc.
The ValidationJob is canceled before it is scheduled again (so theoretically there should be just one validation job running). I've investigated also the cases where the monitor could be cancelled but the ValidationJob continued without checking the cancellation.
The following method implementation is potentially the candidate which could cause this problem:
org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor.updateAnnotations(IProgressMonitor, List, Map<Annotation, Position>)
If the annotationModel is an IAnnotationModelExtension, it delegates the removing / adding of the entries and the replaceAnnotations() method does it iteratively and its not able to check if the monitor was cancelled. (monitor instance isn't forwarded).
Why was the IAnnotationModelExtension check was necessary? Is there a special usecase? If we don't have this check the following lines are also iteratively removing the annotations but also check if the monitor is cancelled (does the same).. Thank you in advance.
Best regards
Mehmet Karaman
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor.updateAnnotations(IProgressMonitor, List, Map<Annotation, Position>) and the stack-trace path through getAnnotationsToRemove and processIssues. Run the described DSL editor testcase involving character edits and Collapse/Expand actions. Done means the sporadic NullPointerException and NoSuchElementException no longer occur during validation.
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
- Needs clarification
- Newbie friendliness
- 35/100