Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337490 - Exception in AbstractEditStrategy
Summary: Exception in AbstractEditStrategy
Status: CLOSED WORKSFORME
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 1.0.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-17 16:36 EST by Samantha Chan CLA
Modified: 2012-11-20 12:44 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samantha Chan CLA 2011-02-17 16:36:05 EST
XText 1.0.2

1)  I have customized content assist to provide a function template when the user invokes content assist.

So, when the user invokes the template, we will insert code like this:

foo(a)

where a is the variable for the user to fill in.

2)  When the user is inside foo(<here, trying to enter the variable), if the user enter double quote, this will invoke the auto code insertion for quotes.

3)  This eventually invoke code in AbstractAutoEditStrategy:

protected String getDocumentContent(IDocument document, DocumentCommand command) {
		if (command.length == 0)
			return document.get();
		try {
			StringBuilder result = new StringBuilder(document.getLength() + command.length);
			if (command.offset > 0)
				result.append(document.get(0, command.offset));
			if (command.offset + command.length < document.getLength())
				result.append(document.get(command.offset + command.length, document.getLength() - command.offset + command.length));
			return result.toString();
		} catch(BadLocationException ex) {
			log.error("Exception in AutoEditStrategy", ex);
			return document.get();
		}
	}

and results in an error like this in the log:
!ENTRY org.apache.log4j 4 0 2011-02-17 14:46:19.946
!MESSAGE org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategy  - Exception in AutoEditStrategy

This is due to a BadLocationException caught in the above function.

I think this function is written incorrectly in the following lines:
if (command.offset + command.length < document.getLength())
				result.append(document.get(command.offset + command.length, document.getLength() - command.offset + command.length));
			return result.toString();

in here document.get(offset, length) is called with 
length = document.getLength - commandoffset + command.length

I think we are missing brackets and this code should be written like this:

f (command.offset + command.length < document.getLength())
				result.append(document.get(command.offset + command.length, document.getLength() - (command.offset + command.length)));  // extra bracket surrounding command.offset + command.length
			return result.toString();
Comment 1 Sven Efftinge CLA 2012-11-20 12:44:37 EST
The brackets woudn't have any effect. Closing this, since it seems to be rather outdated. Please reopen if it's still an issue.