Bug 202689

Summary: NameLookup.findPackageFragments not obeying its contract
Product: [Eclipse Project] JDT Reporter: Robert Konigsberg <konigsberg>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: jerome_lanneluc, jgarms, Olivier_Thomann
Version: 3.4Keywords: needinfo
Target Milestone: 3.5 M3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Robert Konigsberg CLA 2007-09-07 16:03:01 EDT
The code that eventually calls NameLookup is trying to convert the IBinding of a PackageBindingNode to an IJavaElement using binding.getJavaElement.

In this particular case, the call stack for the ASTVisitor that found this PackageBindingNode is:
* CompilationUnit
* ImportDeclaration
* QualifiedName (com.example.foo.bar.AClass)
* QualifiedName(com.example.foo.bar)
* QualifiedName(com.example.foo)


According to the javadoc for NameLookup.findPackageFragments(String, boolean, boolean), it should return the package fragments, or null if none are found. That said, it should never return an empty array.

I've snipped some of the code out of the method.

			Object value = this.packageFragments.get(splittedName); // line 534
			if (value == null)
				return null;
			if (value instanceof PackageFragmentRoot) {
				return new IPackageFragment[] {((PackageFragmentRoot) value).getPackageFragment(splittedName)};
			} else {
				IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
				IPackageFragment[] result = new IPackageFragment[roots.length]; // line 561
				for (int i= 0; i < roots.length; i++) {
					result[i] = ((PackageFragmentRoot) roots[i]).getPackageFragment(splittedName);
				}
				return result;
			}

Here's what happens when I call QualifiedName(com.example.foo).resolveBinding().getJavaElement():

value on line 534 is not null, but it's IPackageFragmentRoot[0].
result on line 561 is turned into IPackageFragment[0], which is returned, and invalid.
Now, the entire project does not compile, so maybe that's a hint as to why I'm finding this problem. Dunno.
Comment 1 Robert Konigsberg CLA 2007-09-07 16:11:15 EDT
Incidentally, this results in org.eclipse.jdt.core.dom.PackageBinding.getJavaElement throwing an IndexOutOfBoundsException.
Comment 2 Jerome Lanneluc CLA 2007-09-10 05:20:53 EDT
Please provide build ID, and exact steps to reproduce.
Comment 3 Jerome Lanneluc CLA 2008-08-26 07:27:59 EDT
Not enough information. Closing as INVALID
Comment 4 Olivier Thomann CLA 2008-09-15 09:09:12 EDT
Reopen to close as a dup of bug 247205.
Comment 5 Olivier Thomann CLA 2008-09-15 09:09:25 EDT

*** This bug has been marked as a duplicate of bug 247205 ***
Comment 6 Olivier Thomann CLA 2008-09-15 09:24:18 EDT
Remove target.
Comment 7 Jerome Lanneluc CLA 2008-09-18 12:29:44 EDT
This is not a dup of bug 247205. This bug is about NameLookup.findPackageFragments(String, boolean,
boolean) but bug 247205 is about NameLookup.findPackageFragment(IPath).

Closing again as INVALID since not enough information (especially build number) was provided to understand the issue.
Comment 8 Kent Johnson CLA 2008-10-28 12:57:55 EDT
Verified for 3.5M3 using I20081026-2000 build.