Bug 89624

Summary: Open on selection proposes twice the same entry
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jerome_lanneluc
Version: 3.1   
Target Milestone: 3.1 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Screenshot
none
Proposed patch
none
Patch with time tracing none

Description Olivier Thomann CLA 2005-03-30 12:45:10 EST
Using 20030330-0500,

I have a java project set as 1.5 compliance and using a 1.5 JDK.

I have the following code:
import java.awt.Frame;
import java.awt.event.WindowAdapter;

public class Foo extends Frame {

    public void bar() {
        addWindowListener(new WindowAdapter());
    }
}

I select WindowAdapter in new WindowAdapter() and press F3. I got two proposals
that are identical. I would expect only one.
Comment 1 Olivier Thomann CLA 2005-03-30 12:46:19 EST
Created attachment 19355 [details]
Screenshot
Comment 2 Olivier Thomann CLA 2005-03-30 12:47:45 EST
Also once I cancel the dialog, I got a bip and a message in the status bar that
says:
"Current text selection does not resolve to a Java element".

I don't expect this error.
Comment 3 Dirk Baeumer CLA 2005-03-30 13:19:16 EST
JDT/Core reports two different Java elements in this case from
ICodeAssist#codeSelect. I have opened bug 89631 for the beep when the dialog get
canceled.
Comment 4 Olivier Thomann CLA 2005-03-30 13:46:59 EST
I might expect two entries because I have JDK1.4.2 and 1.5.0 in the workspace.
But I don't expect the entry to be displayed with the same label.
If you use Ctrl + Shift + T, and type WindowAdapter, the right two entries are
displayed.
Comment 5 Olivier Thomann CLA 2005-03-30 15:44:57 EST
This seems to be a problem in the Java model.
Simple test case:
1) Create a java project
2) Create a package fragment pack in which you had the following CU:
package pack;
import pack.*;
public class A {
}

3) Select pack in the package declaration and press F3.
4) You end up with a dialog with two identical entries in it.

Put a breakpoint:
org.eclipse.jdt.internal.core.SelectionRequestor line 374
	IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(new
String(packageName), false);

There are two package fragments returned from that call. I would expect only
one. This could lead to different kinds of problems (memory consumption,
duplicates in multiple dialogs).
Raise severity as major.

Jérôme, any idea what could be wrong?
Comment 6 Jerome Lanneluc CLA 2005-03-30 16:32:45 EST
Namelookup is adding the package of the working copy a second time.
Note problem existed in 3.1 M5a
Comment 7 Jerome Lanneluc CLA 2005-03-30 16:33:19 EST
Created attachment 19379 [details]
Proposed patch
Comment 8 Jerome Lanneluc CLA 2005-03-30 16:34:09 EST
Need to check performance before releasing this patch.
Comment 9 Philipe Mulet CLA 2005-03-30 16:35:15 EST
+1 for M6
Comment 10 Jerome Lanneluc CLA 2005-03-31 03:33:31 EST
Created attachment 19395 [details]
Patch with time tracing
Comment 11 Jerome Lanneluc CLA 2005-04-01 03:30:32 EST
Not a regression comparing to 3.1 M5. Will fix in 3.1 M7.
Comment 12 Jerome Lanneluc CLA 2005-04-22 10:45:31 EDT
Released patch and added regression test
NameLookupTests2#testFingPackageFragementWithWorkingCopy()
Comment 13 Frederic Fusier CLA 2005-05-12 07:26:58 EDT
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.