Unclear error message when class has same name as package

Jeremy Manson jeremymanson at google.com
Mon Aug 19 12:52:29 PDT 2013


Okay, thanks for the attention, Jon.  I didn't feel too strongly about it;
it was just that a user had mentioned it, and it did seem less than ideal
from a usability POV.

Jeremy


On Tue, Aug 13, 2013 at 3:32 PM, Jonathan Gibbons <
jonathan.gibbons at oracle.com> wrote:

>  Jeremy,
>
> To be realistic, I do not know what we can do about this issue.  It is
> legal to have a class and a package with the same name, which means that in
> a sufficiently perverse case, and the following import
>
>     import A.B.C.D.E;
>
> the problem could occur at any point along the qualified name, where the
> compiler chooses a type name contrary to the erroneous expectation of the
> programmer. See JLS 6.5.4.
>
> So, as much as it would be nice to be able to warn the programmer of
> problematic coding, this error message is not the place to do it.    The
> compiler already tries to give you enough detail by point out (in your
> case) that it is trying to find "class E" within "class D".   That should
> surely be enough to have you realize that the compiler is looking at "class
> D" and not "package D".
>
> -- Jon
>
>
>
> On 08/13/2013 12:36 PM, Jeremy Manson wrote:
>
> Thanks!
>
>  Jeremy
>
>
> On Tue, Aug 13, 2013 at 2:31 AM, Vicente-Arturo Romero-Zaldivar <
> vicente.romero at oracle.com> wrote:
>
>> Hi Jeremy,
>>
>> Thanks for the report I have created a bug entry with id JDK-8022873 to
>> track this issue,
>>
>> Vicente
>>
>>
>> On 10/08/13 23:10, Jeremy Manson wrote:
>>
>>> Hi folks,
>>>
>>> One of our users said that he spent a day trying to figure out where how
>>> this error happened (lots of autogenerated code made it all rather opaque),
>>> so I'm reporting it.
>>>
>>> $ cat C.java
>>> import p.D.E;
>>>
>>> public class C {
>>> }
>>> $ cat p/D.java
>>> package p;
>>> public class D {
>>> }
>>> $ cat p/D/E.java
>>> package p.D;
>>>
>>> public class E {
>>> }
>>> $ javac C.java
>>> C.java:1: error: cannot find symbol
>>> import p.D.E;
>>>           ^
>>>   symbol:   class E
>>>   location: class D
>>> 1 error
>>>
>>>
>>> The reporter suggested that the error "cannot find symbol" would be
>>> better as something like "package D clashes with class of same name".
>>>
>>> Jeremy
>>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20130819/65519e7b/attachment.html 


More information about the compiler-dev mailing list