Bug 243406 - [code assist] Content assist gives "assertion failed" for import Foo|.Bar
Summary: [code assist] Content assist gives "assertion failed" for import Foo|.Bar
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 273206 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-08-07 09:04 EDT by Ary Borenszweig CLA
Modified: 2009-05-07 03:33 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (4.04 KB, patch)
2009-03-05 08:47 EST, 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 Ary Borenszweig CLA 2008-08-07 09:04:31 EDT
Build ID: I20080617-2000

Steps To Reproduce:
1. Create a Java Project.
2. Create a package foo.
3. Create a class named Test in the default package.
4. Create a class named Test2 in package foo
5. Type the following in class Test:

---
import Test2.Foo

public class Test {

}
---

6. Place the cursor exactly after the word "Test2" and request autocomplete (ctrl+space). I get a popup saying ""Content Assist" did not complete normally.  Please see the log for more information."

And here's the error log:

org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:111)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:97)
at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.setCursorPosition(AbstractJavaCompletionProposal.java:280)
at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.setCursorPosition(LazyJavaCompletionProposal.java:176)
at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:419)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:923)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$21(CompletionProposalPopup.java:887)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:492)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:479)
at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1664)
at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:177)
at org.eclipse.ui.texteditor.ContentAssistAction$1.run(ContentAssistAction.java:82)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.texteditor.ContentAssistAction.run(ContentAssistAction.java:80)
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:471)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:822)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:880)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:569)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:511)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:126)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1184)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1002)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1040)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1036)
at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1352)
at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3894)
at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:341)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3787)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2370)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
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:193)
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:382)
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:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)



More information:
Comment 1 Olivier Thomann CLA 2008-08-07 09:46:03 EDT
Move to JDT/Text
Comment 2 Dani Megert CLA 2008-08-07 10:57:05 EDT
Back to JDT Core: org.eclipse.jdt.core.CompletionProposal.getReplaceStart() gives a wrong (to big) value.
Comment 3 Dani Megert CLA 2008-08-07 11:32:12 EDT
Note that it's even questionable to propose "p . T e s t 2 ;]" here as this results in a compiler error.
Comment 4 Ary Borenszweig CLA 2008-08-07 12:34:10 EDT
I'd like the proposal "foo.Test2", to replace "Test2".

In my original scenario, I had something like this:

public class Test2 {

  public static enum Operator {
    And, Or
  }

}

So I typed in another class, in the imports section (I had "Test2.Operator" in the clipboard):

import static Test2.Operator.*;

Then I noticed a compiler error, because Test2 wasn't found because it isn't qualified. So I put the cursor after Test2, requested autocomplete and got the problem. That's why I was expecting the proposal to replace "Test2" with "foo.Test2", which in this case doesn't result in a compiler error.
Comment 5 Dani Megert CLA 2008-08-07 15:52:46 EDT
By all means, we live in 2008: don't hack imports by hand. Simply use Organize Imports (Ctrl+Shift+O) or even better, let the Save actions do it for you ;-)
Comment 6 Ary Borenszweig CLA 2008-08-07 16:18:24 EDT
I use organize imports all the time, but see my original scenario. I want "And" or "Or" to remain in my code, not "Operator.And" or "Test2.Operator.And". But organize imports doesn't add an "import static Test2.Operator.*" if it encounters "And" or "Or".

Suppose I have a method in another class that accepts an Operator. In the caller, I only want to type "And" or "Or", so the import for "Test2.Operator" is not present already. And organize imports doesn't work for that. That's what I mean. That's the only situation where I need to add an import by hand: if it's static.
Comment 7 Dani Megert CLA 2008-08-08 09:04:45 EDT
Makes sense. If you use that Operator often you can add it to the Content Assist > Favorites. If you do so, you can then type A + code assist and it inserts 'And' plus import for you.
Comment 8 Ary Borenszweig CLA 2008-08-08 09:08:55 EDT
Wow! Thanks! I didn't know that. That is new in 3.4, right?
Comment 9 Dani Megert CLA 2008-08-08 09:27:13 EDT
Nope, that's already in 3.3.x.
Comment 10 Mário Guimarães CLA 2009-01-18 14:07:36 EST
Hi,

this bug also occurs if the programmer places the cursor between characters 't' and 'h', 

import java.lang.Mat|h.PI;

or 'h' and '.', 

import java.lang.Math|.PI;

and then presses CTRL+SPACE.

Note that this occurs whether there is the keyword "static" or not.
Hope this helps somehow.

Regards,
Mário

Comment 11 David Audel CLA 2009-03-05 08:47:04 EST
Created attachment 127648 [details]
Proposed fix
Comment 12 David Audel CLA 2009-03-05 08:49:17 EST
Released for 3.5M6.

Tests added
  CompletionTests#testCompletionImportedType7() -> testCompletionImportedType8()
Comment 13 Olivier Thomann CLA 2009-03-10 09:32:36 EDT
Verified for 3.5M6 using I20090310-0100.
Comment 14 Dani Megert CLA 2009-04-22 04:17:34 EDT
*** Bug 273206 has been marked as a duplicate of this bug. ***