Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368519 - Exception when toggling comments on the very last line in an xtext editor
Summary: Exception when toggling comments on the very last line in an xtext editor
Status: CLOSED DUPLICATE of bug 470638
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.3.1   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: v2.8.4
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-13 04:17 EST by Laurent CLA
Modified: 2015-06-20 09:57 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent CLA 2012-01-13 04:17:55 EST
Build Identifier: M20110909-1335

If toggling comments on the very last line with and the last line includes 2 or more partitioning (TextUtilities.computePartitioning), then the method ToggleSLCommentAction.getFirstCompleteLineOfRegion asks for the start offset of the following line, which does not exist. It produces a BadLocationException.

!ENTRY org.apache.log4j 4 0 2011-12-20 09:03:58.443
!MESSAGE org.eclipse.xtext.ui.editor.toggleComments.ToggleSLCommentAction -

!STACK 0

org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.TreeLineTracker.fail(TreeLineTracker.java:1055)
	at org.eclipse.jface.text.TreeLineTracker.offsetByLine(TreeLineTracker.java:334)
	at org.eclipse.jface.text.TreeLineTracker.getLineOffset(TreeLineTracker.java:1122)
	at org.eclipse.jface.text.AbstractLineTracker.getLineOffset(AbstractLineTracker.java:169)
	at org.eclipse.jface.text.AbstractDocument.getLineOffset(AbstractDocument.java:922)

at org.eclipse.xtext.ui.editor.toggleComments.ToggleSLCommentAction.getFirstCompleteLineOfRegion(ToggleSLCommentAction.java:207)
at org.eclipse.xtext.ui.editor.toggleComments.ToggleSLCommentAction.isSelectionCommented(ToggleSLCommentAction.java:138)
at org.eclipse.xtext.ui.editor.toggleComments.ToggleSLCommentAction.run(ToggleSLCommentAction.java:90)

	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:468)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1069)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4127)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1457)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1480)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1465)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1494)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1490)
	at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:463)
	at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:1051)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5563)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:68)
	at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:587)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5473)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:220)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2092)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2252)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5535)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:4989)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5138)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3610)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)



Reproducible: Always

Steps to Reproduce:
1. open, e.g, an existing .xtext grammar file
2. go to the last non-empty line and remove all \r\n characters on this line and after
3. add some characters at the end of the line, select them and toggle comments.
Comment 1 Laurent CLA 2013-09-10 10:40:49 EDT
It still occurs in Xtext 2.3.1.
I have not tried Xtext 2.4.3 yet.
Comment 2 Laurent CLA 2013-09-10 10:42:17 EDT
It does not only occurs on MacOS but also in Linux.
And also with Eclipse M20120914-1800.
Comment 3 Sven Efftinge CLA 2013-09-12 03:03:17 EDT
It still happens with 2.4.3
Comment 4 Sebastian Zarnekow CLA 2015-06-20 09:57:13 EDT

*** This bug has been marked as a duplicate of bug 470638 ***