JDK 16 RFR of JDK-8071961: Add javac lint warning when a default constructor is created

Alex Buckley alex.buckley at oracle.com
Mon Aug 17 16:29:33 UTC 2020


On 8/15/2020 10:18 AM, Joe Darcy wrote:
> How about
> 
> class {0} of exported package {1} declares no explicit constructors, 
> exposing a default constructor to clients of module {2}

> javac.opt.Xlint.desc.missing-declared-ctor=\
>      Warn about missing declared constructors in public classes in 
> exported packages.

The warning mentions "explicit" constructors, the help mentions 
"declared" constructors. "declared" is the wrong factoring -- there is 
*always* a constructor declared (either explicitly or implicitly), and 
we want to focus on the omission of an explicit declaration. Saying 
"explicit" sets up the constrast with "implicit", which some people will 
want to use, such as Daniel Fuchs today: "that's what Joe Darcy used to 
document public implicit constructors in abstract classes...". Saying 
"explicit" also allows the contrast with "default"; much better than 
"declared" versus "default".

Recommend:

compiler.warn.missing-explicit-ctor=\
class {0} in exported package {1} declares no explicit constructors, 
exposing a default constructor to clients of module {2}

e.g.
class LineMetrics in exported package java.awt.font declared no explicit 
constructors, exposing a default constructor to clients of module 
java.desktop

javac.opt.Xlint.desc.missing-explicit-ctor=\
Warn about missing explicit constructors in public classes in exported 
packages.

Alex


More information about the compiler-dev mailing list