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

Joe Darcy joe.darcy at oracle.com
Thu Jul 30 01:45:12 UTC 2020


Hello,

On 7/29/2020 5:15 PM, Alex Buckley wrote:
> 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`.

Okay.

>
> 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.


Hmm. How about something like:

     Since it does not declare an explicit constructor, class {0} in 
exported package {1} of module {2} exposes a default constructor

As with a number of terms in the JLS, "default" is used in multiple 
contexts with different meanings ("default methods" vs a "default 
constructor", etc.). The main point to convey here to the reader of the 
message is that the *absence* of something is causing the warning. The 
location the warning is reported is the start of the class declaration.

Cheers,

-Joe



More information about the compiler-dev mailing list