Bug 3955 - Internal errors using Find/Replace Dialog (1GF86V3)
Summary: Internal errors using Find/Replace Dialog (1GF86V3)
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All Windows NT
: P4 minor (vote)
Target Milestone: ---   Edit
Assignee: Erich Gamma CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-10 23:03 EDT by Tod Creasey CLA
Modified: 2001-11-11 12:34 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tod Creasey CLA 2001-10-10 23:03:38 EDT
If you select more than one line and then Find/Replace you get an SWT error

STEPS
	1) Open a text file with multiple lines
	2) Select at least two lines
	3) Select Find/Replace from the popup menu
	4) Hit Replace all - you will get several exceptions

4 org.eclipse.ui 0 Argument not valid
java.lang.IllegalArgumentException: Argument not valid
	java.lang.Throwable(java.lang.String)
	java.lang.Exception(java.lang.String)
	java.lang.RuntimeException(java.lang.String)
	java.lang.IllegalArgumentException(java.lang.String)
	void org.eclipse.swt.SWT.error(int, java.lang.Throwable)
	void org.eclipse.swt.SWT.error(int)
	java.lang.String org.eclipse.jface.text.DocumentAdapter.getLine(int)
	void org.eclipse.swt.custom.StyledText.draw(int, int, int, int, org.eclipse.swt.graphics.GC, boolean)
	void org.eclipse.swt.custom.StyledText.handlePaint(org.eclipse.swt.widgets.Event)
	void org.eclipse.swt.custom.StyledText$11.handleEvent(org.eclipse.swt.widgets.Event)
	void org.eclipse.swt.widgets.EventTable.sendEvent(org.eclipse.swt.widgets.Event)
	void org.eclipse.swt.widgets.Widget.sendEvent(int, org.eclipse.swt.widgets.Event)
	org.eclipse.swt.internal.win32.LRESULT org.eclipse.swt.widgets.Composite.WM_PAINT(int, int)
	int org.eclipse.swt.widgets.Control.windowProc(int, int, int)
	int org.eclipse.swt.widgets.Display.windowProc(int, int, int, int)
	int org.eclipse.swt.internal.win32.OS.DispatchMessage(org.eclipse.swt.internal.win32.MSG)
	boolean org.eclipse.swt.widgets.Display.readAndDispatch()
	void org.eclipse.ui.internal.Workbench.runEventLoop()
	java.lang.Object org.eclipse.ui.internal.Workbench.run(java.lang.Object)
	java.lang.Object org.eclipse.core.internal.boot.InternalBootLoader.run(java.lang.String, java.net.URL, java.lang.String, java.lang.String [])
	java.lang.Object org.eclipse.core.boot.BootLoader.run(java.lang.String, java.net.URL, java.lang.String, java.lang.String [])
	java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object [])
	java.lang.Object org.eclipse.core.launcher.Main.basicRun(java.lang.String [])
	java.lang.Object org.eclipse.core.launcher.Main.run(java.lang.String [])
	void org.eclipse.core.launcher.UIMain.main(java.lang.String [])



NOTES:
WC (12/06/2001 5:03:39 PM)
	Note that it works fine on Windows 2000

KUM (6/13/01 4:16:50 PM)
	The Find/Replace Dialog does not correctly consider the existing line delimiters but works with "\n".

LK (6/13/01 11:13:54 AM)
	Only happens on Replace All with an empty replace string.  If you use a replace string, it works okay.
	If you just use Replace it works okay.  Also note that you do not have to select two lines - if you fully 
	select 1 line (so that you get the line delimiter), the problem will also occur. 

LK (6/13/01 11:50:50 AM)
	Tried a simple case:

		Line1\r\nLine2

	Selected all the text.  Did a Replace All with replace string of "".  At this point, the document should have
	one empty line.  StyledText calls back to the DocumentContent for the width of line 0 (the first line).   The 
	DocumentAdapter method below returns a region with a length of -1, which is causing the BadLocationException
	to be thrown, which is causing the "internal error".
	
		public String getLine(int line) {
			try {
				IRegion r= fDocument.getLineInformation(line);
				return fDocument.get(r.getOffset(), r.getLength());
			} catch (BadLocationException x) {
				SWT.error(SWT.ERROR_INVALID_ARGUMENT);
				return null;
			}
		}

	This is a DocumentAdapter problem.  Also note that while tracing I noticed that the replacedLineCount in the
	TextChangingEvent that is sent by the DocumentAdapter is wrong for the above scenario.  replacedLineCount
	should be 1 (i.e., 2 lines before change, 1 line after change ==> 1 replaced line).

EG (6/13/2001 7:12:59 AM)
	adopting PR

EG (6/13/2001 11:23:29 AM)
	proposed fix is to only take the first line (excluding the line delimitter) from the
	selection as the initial value of the Find entry field. This is consistent with
	what we do in Search and avoids this problem.
	Requesting for OK to fix.
	
EG (6/14/01 9:40:21 AM)
	PR fix proved by KM, KH, GDA, JW

KUM (6/14/01 4:52:19 PM)
	Fixed. Build > 123.

DM (6/18/01 3:55:45 PM)
	Exception is fixed but fix is not user-friendly: the actual replace does
	not replace what's shown in the Find/Replace dialog (i.e. first line of
	selection) but replaces all the initially selected lines.

	Either indicate in the Find/Replace dialog that there are more lines
	selected or (preferred) only replace the first line i.e. what's currently
	shown in the Find/Replace dialog.

EG (7/11/2001 12:46:52 PM)
	only replace first line
Comment 1 Martin Aeschlimann CLA 2001-10-16 11:15:16 EDT
moved to 'active'
Comment 2 DJ Houghton CLA 2001-10-24 07:26:00 EDT
PRODUCT VERSION: 122


Comment 3 Erich Gamma CLA 2001-11-11 12:34:26 EST
closing