Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » EObjectAtOffsetHelper.internalResolveElementAt method is not null safe
EObjectAtOffsetHelper.internalResolveElementAt method is not null safe [message #723484] Thu, 08 September 2011 16:28 Go to next message
Mary Komor is currently offline Mary KomorFriend
Messages: 61
Registered: July 2009
Member
EObjectAtOffsetHelper.internalResolveElementAt makes a call to
NodeModelUtils.findLeafNodeAtOffset, which could return null, but it does
not do a null check of the result and results in an NPE. I got this to
happen when my cursor was at the very end of my file (the resulting offset
was equal to the length of the root node). Should there be a null check? The
workaround I have put into my code is to check the offset that I am asking
to be resolved -- if it is equal to the total length of the root node, then
I decrease it by 1.


Here's the snippet of code in EObjectAtOffsetHelper.internalResolveElementAt

ILeafNode leaf =
NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
if(leaf.isHidden() && leaf.getOffset() == offset) {
leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(),
offset - 1);
}



Mary
Re: EObjectAtOffsetHelper.internalResolveElementAt method is not null safe [message #723524 is a reply to message #723484] Thu, 08 September 2011 18:21 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Hi,

this seems to be already fixed in the latest version
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plugins/org.eclipse.xtext/src/org/eclipse/xtext/resource/EObjectAtOffsetHelper.java

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:maven repository for xtext 2.0.1
Next Topic:Multiple code completion menus
Goto Forum:
  


Current Time: Wed May 08 08:58:46 GMT 2024

Powered by FUDForum. Page generated in 0.04090 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top