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

Alex Buckley alex.buckley at oracle.com
Thu Jul 30 00:15:46 UTC 2020


On 7/29/2020 1:10 PM, Joe Darcy wrote:
> Please review the code changes and CSR for
> 
>      JDK-8071961: Add javac lint warning when a default constructor is 
> created
>      webrev: http://cr.openjdk.java.net/~darcy/8071961.5/
>      CSR: https://bugs.openjdk.java.net/browse/JDK-8250795

I like the idea of warning about irregular aspects of exported classes, 
such as having an implicitly declared ("default") ctor, or implementing 
an unexported interface. These constructs are not always wrong, but they 
affect how code in other modules can couple to code in this module, so 
system architects may appreciate lint warnings in this area.

> The text of the warning message implies what criteria are being used:
> 
>   # 0: symbol, 1: symbol, 2: symbol
>   compiler.warn.default-ctor=\
>       class {0} in exported package {1} of module {2} relies on a 
> default (implicit) constructor

Recommend "exposes" rather than "relies on". We're in the domain of 
modules, where "relies on" / "depends on" will be taken in connection 
with `requires`.

Also, I recommend dropping "(implicit)". I believe the dominant term in 
use is "default", and I think this is not the place for parenthetical 
expressions that can be misinterpreted.

I would even label the warning as exposed-default-ctor. ("A default ctor 
is exposed if it is implicitly declared in a public class of an exported 
package in a named module. If the class is nested, then ...")

Alex


More information about the compiler-dev mailing list