Bug 153130 - [assist] IOB during content assist in scrapbook
Summary: [assist] IOB during content assist in scrapbook
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 M2   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-08 13:38 EDT by Darin Wright CLA
Modified: 2006-09-18 11:15 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (5.41 KB, patch)
2006-09-04 04:52 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Wright CLA 2006-08-08 13:38:04 EDT
I20060807-2000

* Created a new scrapbook page in a 1.5 project
* Tried content assist after "new java.util.ArrayList<"

BOOM:

java.lang.IllegalArgumentException: Index out of bounds
	at org.eclipse.swt.SWT.error(SWT.java:3358)
	at org.eclipse.swt.SWT.error(SWT.java:3297)
	at org.eclipse.swt.SWT.error(SWT.java:3268)
	at org.eclipse.swt.custom.StyledText.getLocationAtOffset(StyledText.java:3685)
	at org.eclipse.jface.text.contentassist.ContentAssistSubjectControlAdapter.getLocationAtOffset(ContentAssistSubjectControlAdapter.java:94)
	at org.eclipse.jface.text.contentassist.ContentAssistant$LayoutManager.getCaretRectangle(ContentAssistant.java:682)
	at org.eclipse.jface.text.contentassist.ContentAssistant$LayoutManager.computeBoundsAboveBelow(ContentAssistant.java:612)
	at org.eclipse.jface.text.contentassist.ContextInformationPopup.resize(ContextInformationPopup.java:440)
	at org.eclipse.jface.text.contentassist.ContextInformationPopup.internalShowContextFrame(ContextInformationPopup.java:360)
	at org.eclipse.jface.text.contentassist.ContextInformationPopup.internalShowContextInfo(ContextInformationPopup.java:280)
	at org.eclipse.jface.text.contentassist.ContextInformationPopup.access$5(ContextInformationPopup.java:275)
	at org.eclipse.jface.text.contentassist.ContextInformationPopup$2.run(ContextInformationPopup.java:262)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.jface.text.contentassist.ContextInformationPopup.showContextInformation(ContextInformationPopup.java:253)
	at org.eclipse.jface.text.contentassist.ContentAssistant.showContextInformation(ContentAssistant.java:1653)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:833)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$22(CompletionProposalPopup.java:770)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:417)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:404)
	at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1582)
	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:777)
	at org.eclipse.ui.texteditor.TextOperationAction$1.run(TextOperationAction.java:131)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:129)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:499)
	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:461)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:424)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:160)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:466)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:799)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:846)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:564)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:506)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:122)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:982)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:927)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:952)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:937)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:965)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:961)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1275)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3352)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3252)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4054)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1928)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2995)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
	at java.lang.reflect.Method.invoke(Method.java:391)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
	at org.eclipse.core.launcher.Main.run(Main.java:977)
	at org.eclipse.core.launcher.Main.main(Main.java:952)
Comment 1 Darin Wright CLA 2006-08-08 14:31:20 EDT
Problem does not occur in 3.2.1, may be a text issue.
Comment 2 Darin Wright CLA 2006-08-08 16:12:58 EDT
Looks like the fix to bug 67328 may have caused this problem? As well, there may be an issue in ContextInformationPopup.createContextFrame(...). In the case of the snippet editor, (offset - beginOffset) is negative, which results in the following line setting visibleOffset to a large number (since subtracting a negative number actually adds it).

int visibleOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x - (offset - beginOffset);
Comment 3 Darin Wright CLA 2006-08-08 16:14:02 EDT
Moving to text for comment/investigation.
Comment 4 Tom Hofmann CLA 2006-08-09 06:36:48 EDT
Hm, the problems seems to be that the completion proposal created by core has wrong offsets: in the given example, the proposal states a completion offset of 155, but a replaceStart and replaceEnd of 24. Apparently, the completion offset was not stripped of any additional context added by the evalutation context. 

(In reply to comment #1)
> Problem does not occur in 3.2.1, may be a text issue.

Context information for parameterized types has newly been introduced for 3.3 M1. Therefore, this was not previously an issue. However, invoking content assist in the following snippet (| == caret) will fail in 3.2 and 20060807:

new java.util.ArrayList().contains(|)

Moving to jdt-core for comments.
Comment 5 Frederic Fusier CLA 2006-08-09 07:31:28 EDT
As David is in vacation, I'm afraid it will be too late for 3.3 M1. I'll try to investigate a little bit and let you know...
Comment 6 Frederic Fusier CLA 2006-08-09 10:23:20 EDT
Unfortunately the changes is not really easy => reset bug's target

Simple test case to highlight this issue (completion is done at |):
public class Test {
	void foo() {
	    new java.util.ArrayList|
	}
}
proposal is ArrayList<E> - java.util
select it and hit enter complete to new java.util.ArrayList<E>: OK

public class Test {
	void foo() {
	    new java.util.ArrayList<|
	}
}
proposal is ArrayList<E> - java.util
select it and hit enter: nothing is inserted

In the latter case, proposal completionName has no chars and selectionRange is empty...
Comment 7 David Audel CLA 2006-09-04 04:51:39 EDT
Behavior described in comment 6 are the expected behavior.
When 'ArrayList<' is completed the ArrayList type is a proposal and nothing is inserted.

The exception occurs only in scrapbook page. The offset of the code snippet isn't correct in EvaluationContext#complete.
Comment 8 David Audel CLA 2006-09-04 04:52:12 EDT
Created attachment 49329 [details]
Proposed fix
Comment 9 David Audel CLA 2006-09-04 04:56:03 EDT
Released for 3.3 M2.

Test added
   CompletionTests_1_5#testEC001()
Comment 10 Frederic Fusier CLA 2006-09-18 11:15:24 EDT
Verified for 3.3 M2 using build I20060918-0010.

Note that you need to have preference "Insert single proposition automatically" set to get this exception. Otherwise, proposal is made correctly and exception occurs in log while inserting it...