Misleading compiler.err.cant.apply.symbol.1 when base class constructor is inaccessible
Daniel Trebbien
dtrebbien at gmail.com
Fri Nov 24 20:10:29 UTC 2017
As reported here 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/20171124/b109d74a/attachment.html>
More information about the compiler-dev
mailing list