Misleading compiler.err.cant.apply.symbol.1 when base class constructor is inaccessible
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Nov 27 11:05:16 UTC 2017
Done
https://bugs.openjdk.java.net/browse/JDK-8191896
Maurizio
On 25/11/17 03:31, Daniel Trebbien wrote:
> Should an issue be created for this in the JDK Bug System? I don't
> have the ability to do this myself.
>
> On Fri, Nov 24, 2017 at 1:28 PM, Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>
> You are right - this is a long standing behavior - in javac the
> accessibility check is done very late, typically after checking
> for applicability; on the other hand, the JLS rules out candidates
> very early in the overload resolution process, so in this case the
> JLS would say there's no constructor. I believe the spirit of the
> implemented logic was to provide more information to the user,
> rather than just say 'cannot find symbol', but I agree with you
> that, while this normally works ok, in this specific case the
> error message ends up being misleading.
>
> Thanks
> Maurizio
>
>
> On 24/11/17 20:10, Daniel Trebbien wrote:
>> As reported here
>> https://netbeans.org/bugzilla/show_bug.cgi?id=222487#c2
>> <https://netbeans.org/bugzilla/show_bug.cgi?id=222487#c2>
>> javac can produce a misleading
>> compiler.err.cant.apply.symbol.1 error message in cases where the
>> base class constructor is inaccessible, either because it is
>> private or package-private.
>>
>> Take the following two files:
>>
>> // base/Base.java
>> package base;
>> public class Base {
>> Base(String value) { }
>> }
>>
>> // Derived.java
>> import base.Base;
>> public class Derived extends Base { }
>>
>> javac 9.0.1 produces the following:
>>
>> src/Derived.java:2: error: constructor Base in class Base cannot
>> be applied to given types;
>>
>> public class Derived extends Base { }
>>
>> ^
>>
>> required: String
>>
>> found: no arguments
>>
>> reason: actual and formal argument lists differ in length
>>
>>
>> This is misleading because it implies that by adding a Derived
>> constructor to call Base(String), that the error can be fixed;
>> however, doing so results in a compiler.err.report.access error
>> because the Base(String) constructor is not accessible:
>>
>> src/Derived.java:4: error: Base(String) is not public in Base;
>> cannot be accessed from outside package
>>
>> super(value);
>>
>> ^
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20171127/194241ee/attachment.html>
More information about the compiler-dev
mailing list