Bug 35128 - Problems with packages named "java"
Summary: Problems with packages named "java"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.1 RC3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 33885 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-17 06:11 EST by John Whaley CLA
Modified: 2003-03-19 07:08 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Whaley CLA 2003-03-17 06:11:04 EST
Eclipse seems to have problems parsing fully-qualified package names when part 
of the package name matches another type.  This prevents Eclipse from 
compiling the joeq project successfully (http://joeq.sf.net/).

Here is a simple test case:

/*** ClassLib/Common/Bar.java ***/
package ClassLib.Common;
public class Bar {
    public java.lang.Object baz() {
        ClassLib.Common.java.lang.Object.foo();
        return null;
    }
}

/*** ClassLib/Common/java/lang/Object.java ***/
package ClassLib.Common.java.lang;
public class Object {
    public static void foo() { }
}



In the baz() method, Eclipse says "ClassLib.Common.java cannot be resolved".  
In the editor, it has a red underline under "ClassLib.Common.java.lang.Object".

If you change the return value of baz() from "java.lang.Object" to 
just "Object", it will work.  In fact, as long as the return type declaration 
starts with "java.lang.", it triggers the bug.

This bug has been present in Eclipse since at least 2.0.  It is still in RC2.
Note: This looks like it may be similar to Bug #33885.
Comment 1 Philipe Mulet CLA 2003-03-17 07:45:02 EST
Reproduced
Comment 2 Philipe Mulet CLA 2003-03-17 07:52:46 EST
When using the batch compiler, it works fine. Problem would seem to be located 
in the builder name environment.

Also, only incremental builds are fooled. Full build does work fine (same issue 
in SearchableEnvironment though).
Comment 3 Philipe Mulet CLA 2003-03-17 08:16:27 EST
Problem is actually in namelookup itself (not in name environment). The 
incremental scenario exposes the bug since 'java' is resolved as a supertype 
before ClassLib/Common/java gets created as a package.

The bug is that the package lookup isn't performed if a notFound type got 
cached.

Same problem should be reproduceable with batch compiler (if Object isn't 
passed on the command line).
Comment 4 Philipe Mulet CLA 2003-03-17 08:19:20 EST
Proposed fix on PackageBinding:

public Binding getTypeOrPackage(char[] name) {
	PackageBinding packageBinding = getPackage0(name);
	if (packageBinding == null) {
		// find the package
		packageBinding = findPackage(name);
	}
	if (packageBinding != null && packageBinding != 
LookupEnvironment.TheNotFoundPackage)
		return packageBinding;

	ReferenceBinding typeBinding = getType0(name);
	if (typeBinding != null && typeBinding != 
LookupEnvironment.TheNotFoundType) {
		if (typeBinding instanceof UnresolvedReferenceBinding)
			typeBinding = ((UnresolvedReferenceBinding) 
typeBinding).resolve(environment);
		if (typeBinding.isNestedType())
			return new ProblemReferenceBinding(name, 
InternalNameProvided);
		return typeBinding;
	}

	if (typeBinding == null) {
		// if no package was found, find the type named name relative 
to the receiver
		if ((typeBinding = environment.askForType(this, name)) != null) 
{
			if (typeBinding.isNestedType())
				return new ProblemReferenceBinding(name, 
InternalNameProvided);
			return typeBinding;
		}

		// Since name could not be found, add problem bindings
		// to the collections so it will be reported as an error next 
time.
		addNotFoundPackage(name);
		addNotFoundType(name);
	} else {
		if (packageBinding == LookupEnvironment.TheNotFoundPackage)
			packageBinding = null;
		if (typeBinding == LookupEnvironment.TheNotFoundType)
			typeBinding = null;
	}

	if (packageBinding != null)
		return packageBinding;
	else
		return typeBinding;
}
Comment 5 Philipe Mulet CLA 2003-03-17 08:19:59 EST
Kent - pls verify my proposed fix. If ok, will escaladate it for RC3
Comment 6 Philipe Mulet CLA 2003-03-17 08:24:24 EST
Indeed, was able to reproduce with batch compiler if Object is only available 
through the classpath.
Comment 7 Frank Sauer CLA 2003-03-17 08:56:16 EST
Could this be the cause for bug 34708 as well?
Comment 8 Philipe Mulet CLA 2003-03-17 09:33:31 EST
It indeed feels the same, also see my comment in bug 34708.
Comment 9 Philipe Mulet CLA 2003-03-17 10:49:31 EST
*** Bug 34708 has been marked as a duplicate of this bug. ***
Comment 10 Philipe Mulet CLA 2003-03-17 10:52:43 EST
Erich - Need approval for releasing this fix into RC3
Comment 11 Erich Gamma CLA 2003-03-17 10:57:23 EST
approve
Comment 12 Philipe Mulet CLA 2003-03-17 10:59:31 EST
Fixed in latest
Comment 13 Philipe Mulet CLA 2003-03-17 11:04:01 EST
Patch available at:

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/jdt-core-
home/patches/org.eclipse.jdt.core_2.1.0.zip
Comment 14 Philipe Mulet CLA 2003-03-17 11:04:40 EST
*** Bug 33885 has been marked as a duplicate of this bug. ***
Comment 15 Philipe Mulet CLA 2003-03-17 14:59:52 EST
Kent - with last version of fix (Scope method, with getTypeOrPackage in place 
of findType), I am wondering if we are not missing the following 2 things which 
happened with #findType invocation:
- reference recording
- visibility check
Comment 16 Frank Sauer CLA 2003-03-17 15:02:01 EST
sounds to me like you're at least missing two regression tests.... :-)
Comment 17 Kent Johnson CLA 2003-03-17 15:36:34 EST
I added the reference recording.

As for the type being visible - its always visible since we're looking in the 
same package.

Frank: Are you volunteering? ;)
Comment 18 Frank Sauer CLA 2003-03-17 15:53:38 EST
Man, I wish I had the time. I'd love to work on this stuff....
Comment 19 John Whaley CLA 2003-03-17 16:09:30 EST
Thanks, your patch fixes the problem.
I just went to sleep and when I woke up the bug was fixed!
This has been annoying me for the past six months, but I would work around it 
by using Jikes as an external compiler and always doing a full build.
I'm glad it fixed other people's issues; I couldn't imagine that I was the 
only one who uses package names that clash with system classes/packages.
Thanks again.
Comment 20 Philipe Mulet CLA 2003-03-17 17:09:17 EST
Actually, we have added 2 regression tests for the scenario mentionned in this 
PR: ConformTests.test200() and test201(). But some more help would still be a 
good idea...


Comment 21 David Audel CLA 2003-03-19 07:08:20 EST
Verified.