Bug 321115 - Compiler is not case sensitive with package names
Summary: Compiler is not case sensitive with package names
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-28 08:24 EDT by Krzysztof Kazmierczyk CLA
Modified: 2010-09-14 14:05 EDT (History)
5 users (show)

See Also:


Attachments
testing project.zip (1.86 KB, application/octet-stream)
2010-07-28 08:26 EDT, Krzysztof Kazmierczyk CLA
no flags Details
error message (7.10 KB, image/png)
2010-07-28 09:12 EDT, Krzysztof Kazmierczyk CLA
no flags Details
two projects from test (8.62 KB, application/octet-stream)
2010-08-10 05:14 EDT, Krzysztof Kazmierczyk CLA
no flags Details
Patch under consideration (1.13 KB, patch)
2010-08-11 02:37 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch (2.05 KB, patch)
2010-08-11 13:52 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Same patch with several regression tests (14.39 KB, patch)
2010-08-11 23:07 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Kazmierczyk CLA 2010-07-28 08:24:06 EDT
Build Identifier: I20100608-0911

I am having "The package COM.KKAZMIERCZYK.test.Broken collides with a type". The problem is caused I am having also my com.kkazmierczyk.test.Broken class in my project.

Although there is convention to name packages with lower case, it is a bug in Eclipse compiler.

Given code compiles in Java compiler.

Reproducible: Always

Steps to Reproduce:
1. Create class com.kkazmierczyk.test.Broken
2. Try to create class COM.KKAZMIERCZYK.test.Broken. You will receive error
Comment 1 Krzysztof Kazmierczyk CLA 2010-07-28 08:26:40 EDT
Created attachment 175395 [details]
testing project.zip

Attaching project with classes com.kkazmierczyk.test.Broken and COM.KKAZMIERCZYK.test.Broken
Comment 2 Ayushman Jain CLA 2010-07-28 09:00:22 EDT
(In reply to comment #1)
> Created an attachment (id=175395) [details]
> testing project.zip
> 
> Attaching project with classes com.kkazmierczyk.test.Broken and
> COM.KKAZMIERCZYK.test.Broken

I think the problem here is not about lowercase or uppercase. You have a TYPE com.kkazmierczyk.test.Broken already defined, and then you're trying to define a PACKAGE with the same name. This is where the conflict is and this is what Eclipse is warning you about. So I think this is a legal error.
Srikanth, what do you think?
Comment 3 Krzysztof Kazmierczyk CLA 2010-07-28 09:12:19 EDT
Created attachment 175400 [details]
error message
Comment 4 Krzysztof Kazmierczyk CLA 2010-07-28 09:16:00 EDT
> I think the problem here is not about lowercase or uppercase. You have a TYPE
> com.kkazmierczyk.test.Broken already defined, and then you're trying to define
> a PACKAGE with the same name. This is where the conflict is and this is what
> Eclipse is warning you about. So I think this is a legal error.
> Srikanth, what do you think?

Ayushman is Java case insensitive on package names? I have type com.kkazmierczyk.test.Broken and want to create package COM.KKAZMIERCZYK.test.Broken which differs than type in case.
Comment 5 Krzysztof Kazmierczyk CLA 2010-08-02 03:47:29 EDT
Ayushman, Srikanth: according to the comment 4 and other, is it valid bug for you?
Comment 6 Ayushman Jain CLA 2010-08-02 07:50:02 EDT
(In reply to comment #5)
> Ayushman, Srikanth: according to the comment 4 and other, is it valid bug for
> you?

We're still not very clear if this is a bug. Here's what I did to reproduce the case:
1) Create a package com.kkazmierczyk.test
2) In above package, create class Broken.java
3) Create another package COM.KKAZMIERCZYK.test.Broken
4) <LINUX ONLY> Create D.java in above package.

In Linux, Eclipse allowed me to do the step 3, and the file D.java had no conflict errors.
In Windows, I was not allowed to do step 3 at all!
So this seems more like an OS-related issue to me. I want to ask you:
- Which OS are you using?
- Did you create the project on Linux and import it on Eclipse in windows?

Please clarify the above points. Thanks
Comment 7 Srikanth Sankaran CLA 2010-08-02 23:52:46 EDT
(In reply to comment #4)

[...]

> Ayushman is Java case insensitive on package names? I have type
> com.kkazmierczyk.test.Broken and want to create package
> COM.KKAZMIERCZYK.test.Broken which differs than type in case.


(In reply to comment #5)
> Ayushman, Srikanth: according to the comment 4 and other, is it valid bug for
> you?

Though the JLS3 does not spell this explicitly, from a reading of section
7.2 Host Support for Packages and 7.2.1 Storing Packages in a File System
we can conclude that a host may be constrained by external limitation to
make package names case insensitive.

The type collides with package diagnostic is a valid one as it creates room
for ambiguity: should a type reference Broken.D at some place refer to (the
non existent) inner type D of Broken class or to a top level type D of
the package Broken ?
Comment 8 Srikanth Sankaran CLA 2010-08-03 00:12:13 EDT
See that on Windows, javac fails with the exact same message:

C:\jtests>type bug\Broken.java
package bug;
public class Broken {
}

C:\jtests>type bug\Broken\D.java
package bug.Broken;
public class D {
}

C:\jtests>C:\ibm-java2-sdk-50-win-i386\bin\javac.exe -Xlint:unchecked -Xlint:dep
recation -Xlint:rawtypes -classpath . -sourcepath c:\jtests;c:\jtests\bug;c:\jte
sts\bug\broken bug\broken\D.java
bug\broken\D.java:1: package bug.Broken clashes with class of same name
package bug.Broken;
^
1 error
Comment 10 Krzysztof Kazmierczyk CLA 2010-08-03 02:48:25 EDT
(In reply to comment #8)
> See that on Windows, javac fails with the exact same message

srikanth, please notice that my case is slightly different than yours:
C:\jtests>type bug\Broken.java
package bug;
public class Broken {
}

C:\jtests>type bug\Broken\D.java
package BUG.Broken;
public class D {
}

javac.exe -Xlint:unchecked
-Xlint:dep
recation -Xlint:rawtypes -classpath . -sourcepath
c:\jtests;c:\jtests\bug;c:\jte
sts\bug\broken bug\broken\D.java

Note - I am using Oracle JVM
Comment 11 Srikanth Sankaran CLA 2010-08-03 05:12:58 EDT
(In reply to comment #10)
> (In reply to comment #8)
> > See that on Windows, javac fails with the exact same message
> 
> srikanth, please notice that my case is slightly different than yours:
> C:\jtests>type bug\Broken.java
> package bug;
> public class Broken {
> }
> 
> C:\jtests>type bug\Broken\D.java
> package BUG.Broken;
> public class D {
> }

Here is a sequence of things as they happen, as I import the project
into eclipse (on windows)

1. Eclipse compiles Broken.java without an error.
2. When compiling D.java, eclipse first issues an
error message saying:
"The declared package "COM.KKAZMIERCZYK.test.Broken" does not match the expected package com.kkazmierczyk.test.Broken" - This is because the compiler treats
the package names as being case sensitive as it should.

(3) Then the compiler internally adjusts the package to be com.kkazmierczyk.test.Broken to reflect the class's real
position in the hierarchical folder structure that models
the package structure.

(4) Having done that the compiler finds that the package name
collides with a type and reports an error.

I don't think there is a bug anywhere here.

Perhaps my code example in comment#8 instead of serving the
intended purpose, only added to the confusion. comment#8 was
just highlighting the fact that javac is also susceptible to
the package name case sensitivity issue. Given the input is
ill formed, the compiler behavior need not necessarily converge.
(I would actually argue that it is a bug in javac that it does
not report the package collides with type message for the snippet
in comment #10)

Bottom line is that case sensitivity or otherwise at the file
system level is outside of a compiler/class loader's purview
and it is a hole in the spec that it does not spell out how an
implementation should handle these issues in a comprehensive
manner. Some of the defects against javac cited earlier pertain
to the specification hole.

Hope this helps.
Comment 12 Krzysztof Kazmierczyk CLA 2010-08-05 09:26:58 EDT
I have found following issue:

My code:
List<String> classFiles = new ArrayList<String>();
classFiles.add("C:\\workspaces\\platform\\test\\src\\com\\kkazmierczyk\\test\\Broken.java");
classFiles.add("C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\C.java");
new org.eclipse.jdt.internal.compiler.batch.Main(new PrintWriter(System.out), new PrintWriter(System.err), false).compile((String[]) classFiles.toArray(new String[classFiles.size()]));

Class Broken is in package com.kkazmierczyk.test 
Class C is in package COM.kkazmierczyk.test.Broken;

When executing the code getting following message:
----------
1. WARNING in C:\workspaces\platform\test\src\com\kkazmierczyk\test\Broken.java (at line 3)
	public class Broken {
	             ^^^^^^
The type Broken collides with a package
----------
----------
2. ERROR in C:\workspaces\platform\test2\src\COM\kkazmierczyk\test\Broken\C.java (at line 1)
	package COM.kkazmierczyk.test.Broken;
	        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The package COM.kkazmierczyk.test.Broken collides with a type
----------
2 problems (1 error, 1 warning)



Is this the bug for you?
Comment 13 Srikanth Sankaran CLA 2010-08-09 04:25:00 EDT
(In reply to comment #12)
> I have found following issue:
> 
> My code:
> List<String> classFiles = new ArrayList<String>();
> classFiles.add("C:\\workspaces\\platform\\test\\src\\com\\kkazmierczyk\\test\\Broken.java");
> classFiles.add("C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\C.java");
> new org.eclipse.jdt.internal.compiler.batch.Main(new PrintWriter(System.out),
> new PrintWriter(System.err), false).compile((String[]) classFiles.toArray(new
> String[classFiles.size()]));
> 
> Class Broken is in package com.kkazmierczyk.test 
> Class C is in package COM.kkazmierczyk.test.Broken;

Could you show the contents of the files ? 

If I have:

C:\>type C:\\workspaces\\platform\\test\\src\\com\\kkazmierczyk\\test\\Broken.ja
va
package com.kkazmierczyk.test;
public class Broken {
        // Empty
}

and

C:\>type C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\
C.java
package com.kkazmierczyk.test.Broken;
public class C {
        // Empty.
}


I get:

----------
1. ERROR in C:\workspaces\platform\test2\src\COM\kkazmierczyk\test\Broken\C.java (at line 1)
	package com.kkazmierczyk.test.Broken;
	        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The package com.kkazmierczyk.test.Broken collides with a type
----------
1 problem (1 error)

While if the contents of C.java were to be

C:\>type C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\
C.java
package COM.kkazmierczyk.test.Broken;
public class C {
        // Empty.
}

I don't get a compile error.

A package can come from multiple fragments and these can be hosted in
different parts of the file system. However many fragments it comes
from there cannot be a collision between a top level type and a package.
This explains the first (error) case.

The second (no error) case shows that package names are case sensitive
and the compiler is indeed treating them as such.

I think in both instances the compiler behavior is correct and I don't
see a bug here.
Comment 14 Ayushman Jain CLA 2010-08-09 04:35:33 EDT
(In reply to comment #13)
[..]
> If I have:
> 
> C:\>type
> C:\\workspaces\\platform\\test\\src\\com\\kkazmierczyk\\test\\Broken.ja
> va
> package com.kkazmierczyk.test;
> public class Broken {
>         // Empty
> }
> 
> and
> 
> C:\>type
> C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\
> C.java
> package com.kkazmierczyk.test.Broken;
> public class C {
>         // Empty.
> }
> 
> 
> I get:
> 
> ----------
> 1. ERROR in
> C:\workspaces\platform\test2\src\COM\kkazmierczyk\test\Broken\C.java (at line
> 1)
>     package com.kkazmierczyk.test.Broken;
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> The package com.kkazmierczyk.test.Broken collides with a type
> ----------
> 1 problem (1 error)
> 
> While if the contents of C.java were to be
> 
> C:\>type
> C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\
> C.java
> package COM.kkazmierczyk.test.Broken;
> public class C {
>         // Empty.
> }
> 
> I don't get a compile error.
> 
> A package can come from multiple fragments and these can be hosted in
> different parts of the file system. However many fragments it comes
> from there cannot be a collision between a top level type and a package.
> This explains the first (error) case.
> 
> The second (no error) case shows that package names are case sensitive
> and the compiler is indeed treating them as such.
> 
> I think in both instances the compiler behavior is correct and I don't
> see a bug here.

Even I dont see a bug here. As stated in comment 6, the Eclipse compiler correctly treats the package names in a case sensitive way. It is actually the operating system which sometimes changes the case. It will be good if you can try this on both linux and windows as per comment 6 and see the difference for yourself.
Comment 15 Krzysztof Kazmierczyk CLA 2010-08-09 04:51:51 EDT
My files:

My content of the files:

C:\workspaces\platform\test\src\com\kkazmierczyk\test\Broken.java:
package com.kkazmierczyk.test;
public class Broken {}

C:\workspaces\platform\test2\src\COM\kkazmierczyk\test\Broken\C.java
package COM.kkazmierczyk.test.Broken;
public class C {}

and from another class executing:
public static void main(String[] args) {
	List<String> classFiles = new ArrayList<String>();
	classFiles.add("C:\\workspaces\\platform\\test\\src\\com\\kkazmierczyk\\test\\Broken.java");
	classFiles.add("C:\\workspaces\\platform\\test2\\src\\COM\\kkazmierczyk\\test\\Broken\\C.java");
	new org.eclipse.jdt.internal.compiler.batch.Main(new PrintWriter(
		System.out), new PrintWriter(System.err), false).compile((String[]) classFiles.toArray(new String[classFiles.size()]));
}

I am having following error:
----------
1. WARNING in C:\workspaces\platform\test\src\com\kkazmierczyk\test\Broken.java (at line 2)
	public class Broken {}
	             ^^^^^^
The type Broken collides with a package
----------
----------
2. ERROR in C:\workspaces\platform\test2\src\COM\kkazmierczyk\test\Broken\C.java (at line 1)
	package COM.kkazmierczyk.test.Broken;
	        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The package COM.kkazmierczyk.test.Broken collides with a type
----------
2 problems (1 error, 1 warning)

Srikanth, can you now reproduce the issue?
Comment 16 Srikanth Sankaran CLA 2010-08-09 05:09:49 EDT
(In reply to comment #15)

> Srikanth, can you now reproduce the issue?

No, this compiles without a problem for me on HEAD (3.7 stream).
Comment 17 Srikanth Sankaran CLA 2010-08-09 17:13:18 EDT
Frederic,

    Perhaps another pair of eyes would help here. Are you able
to see the problem mentioned in comment# 15 using the examples
given there ? I am not.
Comment 18 Frederic Fusier CLA 2010-08-10 04:17:11 EDT
(In reply to comment #17)
> Frederic,
> 
>     Perhaps another pair of eyes would help here. Are you able
> to see the problem mentioned in comment# 15 using the examples
> given there ? I am not.

I also do not see any trouble with the comment 15 sample.

Which version of batch compiler do you use to run your class which compiles the two sources?

Personally, I used ecj-head.jar built from the scripts/export-ecj.xml on top of org.eclipse.jdt.core project R3_6 version. As I said, with this jar, I confirm there's no error while compiling those two sources...
Comment 19 Krzysztof Kazmierczyk CLA 2010-08-10 05:14:18 EDT
Created attachment 176214 [details]
two projects from test

(In reply to comment #18)
> 
> Which version of batch compiler do you use to run your class which compiles the
> two sources?

I checked out org.eclipse.jdt.core (HEAD version) and made dependency to the project from which I am compiling.

I am attaching also my two projects located in c:\workspaces\platform
Comment 20 Frederic Fusier CLA 2010-08-10 05:47:26 EDT
(In reply to comment #19)
> Created an attachment (id=176214) [details]
> two projects from test
> 
> (In reply to comment #18)
> > 
> > Which version of batch compiler do you use to run your class which compiles the
> > two sources?
> 
> I checked out org.eclipse.jdt.core (HEAD version) and made dependency to the
> project from which I am compiling.
> 
> I am attaching also my two projects located in c:\workspaces\platform

I can reproduce while running the compilation from an eclipse session. Hence, it looks like the compiler behavior is different when invoked from batch or from eclipse...
Comment 21 Srikanth Sankaran CLA 2010-08-10 06:14:35 EDT
(In reply to comment #19)
> Created an attachment (id=176214) [details]
> two projects from test
> 
> (In reply to comment #18)
> > 
> > Which version of batch compiler do you use to run your class which compiles the
> > two sources?
> 
> I checked out org.eclipse.jdt.core (HEAD version) and made dependency to the
> project from which I am compiling.
> 
> I am attaching also my two projects located in c:\workspaces\platform

This has quite a bit of extraneous stuff that is causing build path
problems. After I get rid of the swt libraries dependencies and the
associated code, I do get the messages you describe. I'll investigate
and see whether there is a bug here.
Comment 22 Frederic Fusier CLA 2010-08-10 06:26:15 EDT
(In reply to comment #21)
> 
> This has quite a bit of extraneous stuff that is causing build path
> problems. After I get rid of the swt libraries dependencies and the
> associated code, I do get the messages you describe. I'll investigate
> and see whether there is a bug here.

The class A in test project does not have path issue as soon as you import the org.eclipse.jdt.core plugin in your wksp. It seems that the snippet is not meaningful for this bug, hence can be ignored...
Comment 23 Krzysztof Kazmierczyk CLA 2010-08-10 06:39:53 EDT
Frederic, in comment 20 you mentioned you reproduced it while running the compilation from an eclipse session. Did you use jar dependency or project dependency in that case?
Comment 24 Frederic Fusier CLA 2010-08-10 07:01:14 EDT
(In reply to comment #23)
> Frederic, in comment 20 you mentioned you reproduced it while running the
> compilation from an eclipse session. Did you use jar dependency or project
> dependency in that case?

Only the dependency to org.eclipse.jdt.core project which was already set in test project. Of course I imported this plugin in my workspace before to have this dependency honored...
Comment 25 Krzysztof Kazmierczyk CLA 2010-08-10 07:38:12 EDT
(In reply to comment #24)
> (In reply to comment #23)
> > Frederic, in comment 20 you mentioned you reproduced it while running the
> > compilation from an eclipse session. Did you use jar dependency or project
> > dependency in that case?
> 
> Only the dependency to org.eclipse.jdt.core project which was already set in
> test project. Of course I imported this plugin in my workspace before to have
> this dependency honored...

Frederic, I am not sure you properly.
What is the difference between environment from comment 20 when you reproduced the issue and comment 22?
Comment 26 Frederic Fusier CLA 2010-08-10 07:54:51 EDT
(In reply to comment #25)
> 
> Frederic, I am not sure you properly.
> What is the difference between environment from comment 20 when you reproduced
> the issue and comment 22?

In fact I did exactly the same that what you did in comment 19 and so, I was able to reproduce the compiler errors while running test/src/com/kkazmierczyk/A as a Java Application inside my eclipse session.

I just added comment 22 to precise that I also imported the org.eclipse.jdt.core plugin to honor the test project dependency. Of course, that was necessary to run A as a Java Application...

It seems that Srikanth was puzzled (as I was initially) by the Snippet262.java class which contains many compiler errors due to unresolved dependency to org.eclipse.swt plugin. But I discovered it was not necessary to use this class to be able to reproduce the problem. That's why I advice him to ignore it.

Hope this is clear now...
Comment 27 Srikanth Sankaran CLA 2010-08-10 08:21:41 EDT
(In reply to comment #21)

> I'll investigate and see whether there is a bug here.

Krzysztof, I confirm that this is an eclipse bug. Thanks
for your patience and persistence. If we had the projects
zipped up initially itself, we would have discovered it
sooner. With plain file system entries, this problem does
not/will not show up which is what we trying to do based
on the initial instructions. This needs an eclipse project
with class path set up to show up.

I have a tentative fix. Stay tuned.
Comment 28 Srikanth Sankaran CLA 2010-08-11 02:37:25 EDT
Created attachment 176298 [details]
Patch under consideration

This bug does not show up inside the IDE if the
IDE is used build the two projects.

Nor will the problem show up if the batch compiler
is invoked directly to compile the files.

Only when a hybrid model is contrived 
by invoking the batch compiler programmatically
from within a workspace project AND by passing to
the invocation of the compiler files spanning
multiple workspace projects can one see the
problem.

Ayush, please review. There is no regression test.
I don't think it is worth it and the code is
straight forward enough.
Comment 29 Srikanth Sankaran CLA 2010-08-11 03:59:57 EDT
Comment on attachment 176298 [details]
Patch under consideration

This patch fails some tests, Looking into it.
Comment 30 Srikanth Sankaran CLA 2010-08-11 13:52:00 EDT
Created attachment 176382 [details]
Revised patch

Fixes the problem with the earlier patch.
All tests pass, Ayush please review. TIA.
Comment 31 Srikanth Sankaran CLA 2010-08-11 23:07:59 EDT
Created attachment 176430 [details]
Same patch with several regression tests

Ayush, please review, TIA.
Comment 32 Ayushman Jain CLA 2010-08-19 02:21:45 EDT
(In reply to comment #31)
> Created an attachment (id=176430) [details]
> Same patch with several regression tests
> 
> Ayush, please review, TIA.

The fix is fine. However, tests test0307, test0307b and test0307c dont really look like they have anything to do with the fix. They pass without the fix as well. Is this intended?
Comment 33 Srikanth Sankaran CLA 2010-08-19 02:39:56 EDT
(In reply to comment #32)

> The fix is fine. However, tests test0307, test0307b and test0307c dont really
> look like they have anything to do with the fix. They pass without the fix as
> well. Is this intended?

Yes, the other tests are simply asserting that our behavior with respect
to type names, nested members etc is case sensitive.

Released in HEAD for 3.7 M2.
Comment 34 Ayushman Jain CLA 2010-09-14 14:05:09 EDT
Verified for 3.7M2 using build I20100909-1700.