Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345874

Summary: [nodemodel] NPE when calling NodeModelUtils.findLeafNodeAtOffset() for RootNode of empty document
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: 2.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: Final   
Hardware: All   
OS: All   
Whiteboard:

Description Knut Wannheden CLA 2011-05-16 02:19:29 EDT
I have a ISelectionChangedListener attached to my XtextSourceViewer which when called, calls (within a readonly transaction) NodeModelUtils#findLeafNodeAtOffset() with XtextResource.getParseResult().getRootNode() as the first argument and the selection offset obtained from the SelectionChangedEvent as the second argument.

If the Xtext document is emtpy (i.e. length == 0) I get the following NPE when calling NodeModelUtils#findLeafNodeAtOffset():


java.lang.NullPointerException
	at org.eclipse.xtext.nodemodel.impl.BasicNodeTreeIterator.hasNext(BasicNodeTreeIterator.java:45)
	at org.eclipse.xtext.nodemodel.util.NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.java:67)

That is because basicGetParent() returned null for the RootNode.
Comment 1 Sebastian Zarnekow CLA 2011-05-30 03:17:16 EDT
Marked as critical since the (Basic)TreeNodeIterator is used at other places, too.
Comment 2 Sebastian Zarnekow CLA 2011-06-03 01:56:29 EDT
Postponed since there are valid workarounds.
Comment 3 Sebastian Zarnekow CLA 2011-07-29 18:02:48 EDT
This one was already resolved with commit a40e333e7c964a391c4179c36afe11011104a3ea

I could reproduce it with the previous version of the iterator but the tests are green for the released version.
Comment 4 Karsten Thoms CLA 2017-09-19 17:50:32 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 18:01:23 EDT
Closing all bugs that were set to RESOLVED before Neon.0