Unclear error message when class has same name as package
Jonathan Gibbons
jonathan.gibbons at oracle.com
Mon Aug 19 13:31:38 PDT 2013
Usability is always a good reason to revisit diagnostics.
We have put work over the last couple of releases to make diagnostics
clearer, at the cost of making them longer. One area where I think we
could wish for more support is better display of diagnostics in an IDE,
such as linking to symbols, using rich text and so on. Also in this
bucket is the general concept of a possible "More Info..." link.
Back on this specific message, although I don't see any obvious easy
improvement, it does seem like we could/should have a lint option for
clashing names -- for example package and class name clash (this case)
or any name clash that might be a problem on systems with
case-equivalent file-systems, or name clashes on systems with reserved
names (CON, COMn, LPTn come to mind.)
-- Jon
On 08/19/2013 12:52 PM, Jeremy Manson wrote:
> 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 <mailto: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 <mailto: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/2159df9e/attachment-0001.html
More information about the compiler-dev
mailing list