JDK 16 RFR of JDK-8250213: Address use of default constructors in com.sun.source.util

Joe Darcy joe.darcy at oracle.com
Thu Jul 23 17:17:09 UTC 2020


Hi Jon,

For the non-abstract classes, I'm happy to change the verbiage to the 
true (if not very informative) "Creates a $FOO."

Longer term, deprecating the unintended constructors for removal would 
be fine too. (This patch is the first in a series to clean-up the JDK 
with the intention of introducing a new lint warning for using default 
constructors.)

Thanks,

-Joe

On 7/23/2020 10:10 AM, Jonathan Gibbons wrote:
> Joe,
>
> If a constructor is documented as being for subclasses to call, it 
> should really be a protected constructor.
>
> Some of the affected classes are abstract, thus forcing the use of 
> subtypes.  Other classes are not abstract although it is hard to 
> imagine a legitimate use for them to be used directly. For those 
> non-abstract classes, should we be looking at a slightly bigger 
> change. If we can't change the signature of the class or constructor, 
> should we at least improve the documentation for these classes? I'm 
> not necessarily suggesting to d that in this changeset; I'm just 
> wondering aloud how best to improve these classes.
>
> -- Jon
>
> On 7/23/20 10:00 AM, Joe Darcy wrote:
>> Hello,
>>
>> Please review the webrev and CSR to address:
>>
>>     JDK-8250213: Address use of default constructors in 
>> com.sun.source.util
>>     webrev: http://cr.openjdk.java.net/~darcy/8250213.0/
>>     CSR: https://bugs.openjdk.java.net/browse/JDK-8250215
>>
>> For the com.sun.source classes, I add the previous implicit public 
>> no-arg constructors as all those classes look to intend to allow 
>> instantiation of themselves or of subclasses. For 
>> com.sun.tools.javac.Main, the constructor seems unintended as all the 
>> members of the class are static.
>>
>> Patch below; before pushed, I'll update the copyright years, etc.
>>
>> Thanks,
>>
>> -Joe
>>
>> --- 
>> old/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePathScanner.java 
>> 2020-07-23 09:48:38.498747851 -0700
>> +++ 
>> new/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePathScanner.java 
>> 2020-07-23 09:48:38.082955836 -0700
>> @@ -39,6 +39,11 @@
>>   */
>>  public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
>>      /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public DocTreePathScanner() {}
>> +
>> +    /**
>>       * Scans a tree from a position identified by a tree path.
>>       * @param path the path
>>       * @param p a value to be passed to visitor methods
>> --- 
>> old/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java 
>> 2020-07-23 09:48:39.330331881 -0700
>> +++ 
>> new/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java 
>> 2020-07-23 09:48:38.886553865 -0700
>> @@ -68,6 +68,10 @@
>>   * @since 1.8
>>   */
>>  public class DocTreeScanner<R,P> implements DocTreeVisitor<R,P> {
>> +    /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public DocTreeScanner() {}
>>
>>      /**
>>       * Scans a single node.
>> --- 
>> old/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java 
>> 2020-07-23 09:48:40.109941910 -0700
>> +++ 
>> new/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java 
>> 2020-07-23 09:48:39.682155894 -0700
>> @@ -47,6 +47,11 @@
>>   */
>>  public abstract class DocTrees extends Trees {
>>      /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public DocTrees() {}
>> +
>> +    /**
>>       * Returns a DocTrees object for a given CompilationTask.
>>       * @param task the compilation task for which to get the Trees 
>> object
>>       * @return the DocTrees object
>> --- 
>> old/src/jdk.compiler/share/classes/com/sun/source/util/JavacTask.java 
>> 2020-07-23 09:48:40.873559937 -0700
>> +++ 
>> new/src/jdk.compiler/share/classes/com/sun/source/util/JavacTask.java 
>> 2020-07-23 09:48:40.441775922 -0700
>> @@ -50,6 +50,10 @@
>>   * @since 1.6
>>   */
>>  public abstract class JavacTask implements CompilationTask {
>> +    /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public JavacTask() {}
>>
>>      /**
>>       * Returns the {@code JavacTask} for a {@code 
>> ProcessingEnvironment}.
>> --- 
>> old/src/jdk.compiler/share/classes/com/sun/source/util/TreePathScanner.java 
>> 2020-07-23 09:48:41.721135968 -0700
>> +++ 
>> new/src/jdk.compiler/share/classes/com/sun/source/util/TreePathScanner.java 
>> 2020-07-23 09:48:41.257367951 -0700
>> @@ -43,6 +43,10 @@
>>   * @since 1.6
>>   */
>>  public class TreePathScanner<R, P> extends TreeScanner<R, P> {
>> +    /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public TreePathScanner() {}
>>
>>      /**
>>       * Scans a tree from a position identified by a TreePath.
>> --- 
>> old/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java 
>> 2020-07-23 09:48:42.564713999 -0700
>> +++ 
>> new/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java 
>> 2020-07-23 09:48:42.100945982 -0700
>> @@ -75,6 +75,10 @@
>>   * @since 1.6
>>   */
>>  public class TreeScanner<R,P> implements TreeVisitor<R,P> {
>> +    /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public TreeScanner() {}
>>
>>      /**
>>       * Scans a single node.
>> --- old/src/jdk.compiler/share/classes/com/sun/source/util/Trees.java 
>> 2020-07-23 09:48:43.408292029 -0700
>> +++ new/src/jdk.compiler/share/classes/com/sun/source/util/Trees.java 
>> 2020-07-23 09:48:43.012490015 -0700
>> @@ -53,6 +53,11 @@
>>   */
>>  public abstract class Trees {
>>      /**
>> +     * Constructor for subclasses to call.
>> +     */
>> +    public Trees() {}
>> +
>> +    /**
>>       * Returns a Trees object for a given CompilationTask.
>>       * @param task the compilation task for which to get the Trees 
>> object
>>       * @throws IllegalArgumentException if the task does not support 
>> the Trees API.
>> --- old/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java 
>> 2020-07-23 09:48:44.231880059 -0700
>> +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java 
>> 2020-07-23 09:48:43.812090044 -0700
>> @@ -34,6 +34,8 @@
>>   * module for details on replacement APIs.
>>   */
>>  public class Main {
>> +    @Deprecated(since="16", forRemoval=true)
>> +    public Main(){}
>>
>>      /** Main entry point for the launcher.
>>       *  Note: This method calls System.exit.
>>


More information about the compiler-dev mailing list