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

Bug 207743

Summary: StringIndexOutOfBoundsException in ConsoleDocumentAdapter
Product: [Eclipse Project] Platform Reporter: Anton Leherbauer <aleherb+eclipse>
Component: DebugAssignee: Michael Rennie <Michael_Rennie>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: d.sadilek, daniel_megert, darin.eclipse, dj.houghton, jamesblackburn+eclipse, jonas, philippe_mulet, rfong, tobias.schwarz, wbprio
Version: 3.3Flags: philippe_mulet: pmc_approved+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
patch none

Description Anton Leherbauer CLA 2007-10-29 05:52:24 EDT
This exception occurs when running the snippet of bug 84641 comment 6.

eclipse.buildId=I20070625-1500
java.version=1.6.0_03
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments:  -os win32 -ws win32 -arch x86

Error
Mon Oct 29 10:40:11 CET 2007
Unhandled event loop exception

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.StringIndexOutOfBoundsException: String index out of range: -1)
at org.eclipse.swt.SWT.error(SWT.java:3563)
at org.eclipse.swt.SWT.error(SWT.java:3481)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:126)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3659)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3296)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.charAt(Unknown Source)
at org.eclipse.ui.internal.console.ConsoleDocumentAdapter.countNewLines(ConsoleDocumentAdapter.java:323)
at org.eclipse.ui.internal.console.ConsoleDocumentAdapter.documentAboutToBeChanged(ConsoleDocumentAdapter.java:291)
at org.eclipse.jface.text.AbstractDocument.fireDocumentAboutToBeChanged(AbstractDocument.java:606)
at org.eclipse.jface.text.AbstractDocument.replace(AbstractDocument.java:1072)
at org.eclipse.jface.text.AbstractDocument.replace(AbstractDocument.java:1091)
at org.eclipse.ui.internal.console.ConsoleDocument.replace(ConsoleDocument.java:82)
at org.eclipse.ui.internal.console.IOConsolePartitioner$QueueProcessingJob.runInUIThread(IOConsolePartitioner.java:536)
at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:94)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
... 22 more
Comment 1 Darin Wright CLA 2007-10-29 09:28:39 EDT
Happens on 3.4 as well:

public class CarriageReturn {
    public static void main(String[] args) {
        System.out.print("\r");
    }
}
Comment 2 Darin Wright CLA 2007-10-29 09:54:57 EDT
Created attachment 81452 [details]
patch

Patch. Missing case for a line/document that is only '\r'.
Comment 3 Darin Wright CLA 2007-10-29 09:55:46 EDT
Released to HEAD. Should also fix in 3.3.2.
Comment 4 Darin Wright CLA 2007-10-29 10:33:14 EDT
Fixed in 3.3.2 and HEAD.
Comment 5 Darin Wright CLA 2007-10-29 10:34:11 EDT
Please verify, Mike.
Comment 6 Dani Megert CLA 2007-10-31 08:16:59 EDT
This fix brings more bad than it does good, see bug 208084. This needs to be pulled out for 3.4 M3 and also reverted for 3.3.2.
Comment 7 Michael Rennie CLA 2007-10-31 15:07:47 EDT
re-closing, the patch that fixes 208084 is built on this fix.
Comment 8 Darin Wright CLA 2007-11-20 22:27:06 EST
Needs PMC approval. This fix is really one fix along with the fix for bug 208084
Comment 9 Darin Wright CLA 2007-11-21 16:47:01 EST
*** Bug 208084 has been marked as a duplicate of this bug. ***
Comment 10 Darin Wright CLA 2007-11-21 16:51:02 EST
Justification: Simply a bug in the console that people run into once in a while when the console processes a single '\r' character as one chunk of output.
Comment 11 Philipe Mulet CLA 2007-11-23 09:21:45 EST
+1 for 3.3.2
Comment 12 Darin Wright CLA 2007-12-06 22:14:44 EST
*** Bug 211431 has been marked as a duplicate of this bug. ***
Comment 13 Darin Wright CLA 2008-01-11 09:05:00 EST
*** Bug 215011 has been marked as a duplicate of this bug. ***
Comment 14 Darin Wright CLA 2008-02-06 13:15:51 EST
*** Bug 217976 has been marked as a duplicate of this bug. ***
Comment 15 Daniel A. Sadilek CLA 2008-05-29 11:07:16 EDT
Hello,

I use Eclipse 3.3.2 (M20080221-1800) on Mac OS X Leopard.
I still got ArrayIndexOutOfBoundsExceptions in StyledTextRenderer. For example, in calculateClientArea and textChanging.
I found out that these exceptions only occur if I set a "Fixed width console" in the preferences. The exceptions then occur after the first line with more than the set maximum character width.
I can easily reproduce this error by activating the "Fixed width console" feature and then simply typing in more characters than maximum character width.

Best regards
Daniel Sadilek
Comment 16 Darin Wright CLA 2008-05-29 11:13:06 EDT
(In reply to comment #15)

> I can easily reproduce this error by activating the "Fixed width console"
> feature and then simply typing in more characters than maximum character width.
> Best regards
> Daniel Sadilek

Then please open a new bug with steps and test case.