Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8250241

Address use of default constructors in the java.util.concurrent

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 16
    • core-libs
    • None
    • minimal
    • The explicit constructors are functionally equivalent to the default ones they're replacing.
    • Java API
    • SE

      Summary

      Replace default constructors in java.util.concurrent with equivalent explicit constructors.

      Problem

      Default constructors considered harmful in formal APIs.

      Solution

      Add explicit constructors.

      Specification

      diff -r d62da6fc4074 src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
      --- a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java Thu Jul 23 20:25:41 2020 +0100
      +++ b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java Thu Jul 23 14:59:38 2020 -0700
      @@ -77,6 +77,11 @@
       public abstract class AbstractExecutorService implements ExecutorService {
      
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    public AbstractExecutorService() {}
      +
      +    /**
            * Returns a {@code RunnableFuture} for the given runnable and default
            * value.
            *
      diff -r d62da6fc4074 src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java
      --- a/src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java    Thu Jul 23 20:25:41 2020 +0100
      +++ b/src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java    Thu Jul 23 14:59:38 2020 -0700
      @@ -242,6 +242,11 @@
           private static final int SIGNAL   = 1 << 16; // true if joiner waiting
           private static final int SMASK    = 0xffff;  // short bits for tags
      
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    public ForkJoinTask() {}
      +
           static boolean isExceptionalStatus(int s) {  // needed by subclasses
               return (s & THROWN) != 0;
           }
      diff -r d62da6fc4074 src/java.base/share/classes/java/util/concurrent/RecursiveAction.java
      --- a/src/java.base/share/classes/java/util/concurrent/RecursiveAction.java Thu Jul 23 20:25:41 2020 +0100
      +++ b/src/java.base/share/classes/java/util/concurrent/RecursiveAction.java Thu Jul 23 14:59:38 2020 -0700
      @@ -166,6 +166,11 @@
           private static final long serialVersionUID = 5232453952276485070L;
      
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    public RecursiveAction() {}
      +
      +    /**
            * The main computation performed by this task.
            */
           protected abstract void compute();
      diff -r d62da6fc4074 src/java.base/share/classes/java/util/concurrent/RecursiveTask.java
      --- a/src/java.base/share/classes/java/util/concurrent/RecursiveTask.java   Thu Jul 23 20:25:41 2020 +0100
      +++ b/src/java.base/share/classes/java/util/concurrent/RecursiveTask.java   Thu Jul 23 14:59:38 2020 -0700
      @@ -69,6 +69,11 @@
           private static final long serialVersionUID = 5232453952276485270L;
      
           /**
      +     * Constructor for subclasses to call.
      +     */
      +    public RecursiveTask() {}
      +
      +    /**
            * The result of the computation.
            */
           @SuppressWarnings("serial") // Conditionally serializable
      diff -r d62da6fc4074 src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
      --- a/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java    Thu Jul 23 20:25:41 2020 +0100
      +++ b/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java    Thu Jul 23 14:59:38 2020 -0700
      @@ -65,6 +65,11 @@
      
           private static final long serialVersionUID = 7373984972572414692L;
      
      +    /**
      +     * Constructor for subclasses to call.
      +     */
      +    public AbstractQueuedLongSynchronizer() {}
      +
           /*
            * To keep sources in sync, the remainder of this source file is
            * exactly cloned from AbstractQueuedSynchronizer, replacing class

            darcy Joe Darcy
            darcy Joe Darcy
            Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: