Bug 273721 - styled text: getSelection returns an invalid selection
Summary: styled text: getSelection returns an invalid selection
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-26 09:38 EDT by Tom Hofmann CLA
Modified: 2021-12-29 17:04 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2009-04-26 09:38:28 EDT
StyledText.java R1.475

I can reproducibly get a StyledText instance into a state where the following method fails. It seems that the widget carries a stale selection and has not yet adjusted to a change in its content. However, the (linear) selection returned from styled text should never extend over the content range.

private boolean hasMultiLineSelection(StyledText textWidget) {
	Point selection= textWidget.getSelection();
	int startLine= textWidget.getLineAtOffset(selection.x);
	int endLine= textWidget.getLineAtOffset(selection.y);
	return startLine != endLine;
}

with:

 java.lang.IllegalArgumentException: Index out of bounds
	at org.eclipse.swt.SWT.error(SWT.java:3862)
	at org.eclipse.swt.SWT.error(SWT.java:3796)
	at org.eclipse.swt.SWT.error(SWT.java:3767)
	at org.eclipse.swt.custom.StyledText.getLineAtOffset(StyledText.java:3894)
	at org.eclipse.jface.text.CursorLinePainter.hasMultiLineSelection(CursorLinePainter.java:257)
	at org.eclipse.jface.text.CursorLinePainter.paint(CursorLinePainter.java:225)
	at org.eclipse.jface.text.PaintManager.paint(PaintManager.java:298)
	at org.eclipse.jface.text.PaintManager.access$1(PaintManager.java:296)
	at org.eclipse.jface.text.PaintManager$1.run(PaintManager.java:353)

Steps to reproduce:

- Have the following file:

---------- Foo.java --------
public String foo(){
       return "hi";


}
----------------------------

- open the file in the Java editor
- open the file a second time using the Text editor
- enable block selection mode in the text editor and put the caret anywhere in the whitespace beyond the end of the first line
- in the Java editor, select the range marked with brackets using linear selection mode

pub[lic String foo(){
       return "hi";

]
}

- cut the selected text using Ctrl+X
> Boom
Comment 1 Felipe Heidrich CLA 2009-04-27 15:44:51 EDT
Works for me with: 
Version: 3.5.0
Build id: I20090427-0800


If you reproduce the problem anytime can you answer these questions:

1) from textWidget.getSelection(), which is wrong ? selection.x, selection.y or both

2) is selection.x or selection.y wrong because 'offset < 0' 'offset > getCharCount()' 

3) can you add prints to 
doBlockSelection(boolean)  
doSelection(int)
setSelection(int, int, boolean, boolean)

and find out who is setting the selection to an invalid value ?


Thank you
Comment 2 Felipe Heidrich CLA 2009-05-28 16:35:02 EDT
Do you still have this problem ?

Works for me with RC3 candidate.
Comment 3 Dani Megert CLA 2009-05-29 02:43:21 EDT
>Works for me with RC3 candidate.
Did you test on Vista?
Comment 4 Felipe Heidrich CLA 2009-05-29 09:46:10 EDT
(In reply to comment #3)
> >Works for me with RC3 candidate.
> Did you test on Vista?

Yes, on vista. Can you make it happen, Danni ?
Comment 5 Dani Megert CLA 2009-05-29 09:47:59 EDT
Not on WindowsXP and I don't have a Vista install at hand.
Comment 6 Tom Hofmann CLA 2009-05-29 10:31:50 EDT
I will try to reproduce over the weekend.
Comment 7 Tom Hofmann CLA 2009-05-31 10:55:13 EDT
I can still reliably reproduce given the steps in comment 0 with HEAD of 20090531 (SWT, text components) and RC3 (everything else). The catch block in CursorLinePainter::hasMultiLineSelection is hit everytime.

In addition, I now get the exception below which stems from the same problem. I will try to find out more details.

!ENTRY org.eclipse.ui 4 0 2009-05-31 16:52:29.168
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.IllegalArgumentException: Index out of bounds)
	at org.eclipse.swt.SWT.error(SWT.java:3884)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3855)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3476)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	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:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Caused by: java.lang.IllegalArgumentException: Index out of bounds
	at org.eclipse.swt.SWT.error(SWT.java:3865)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.SWT.error(SWT.java:3770)
	at org.eclipse.swt.custom.StyledText.getLocationAtOffset(StyledText.java:4252)
	at org.eclipse.jface.text.TextViewer.computeVirtualChars(TextViewer.java:2577)
	at org.eclipse.jface.text.TextViewer.getSelection(TextViewer.java:2534)
	at org.eclipse.ui.texteditor.AbstractTextEditor.doGetSelection(AbstractTextEditor.java:2874)
	at org.eclipse.ui.texteditor.AbstractTextEditor$SelectionProvider.getSelection(AbstractTextEditor.java:1486)
	at org.eclipse.ui.texteditor.AbstractTextEditor$9.run(AbstractTextEditor.java:624)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	... 23 more
Comment 8 Eclipse Webmaster CLA 2019-09-06 16:13:01 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 9 Eclipse Genie CLA 2021-12-29 17:04:07 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.