JDK 14 RFR of JDK-8230723: Remove default constructors from java.lang and java.io

Joe Darcy joe.darcy at oracle.com
Fri Sep 6 18:12:31 UTC 2019


Hello,

First part of a multi-part cleanup effort please review

     JDK-8230723: Remove default constructors from java.lang and java.io
     webrev: http://cr.openjdk.java.net/~darcy/8230723.0/
     CSR: https://bugs.openjdk.java.net/browse/JDK-8230724

Patch below.

The default constructors on Modifier and ConstantBootstraps seem clearly 
accidental so I deprecated them for removal.

The PrimitiveSlot and Factory classes are public classes within 
non-public classes so I made the constructors package private rather 
than public. However, this is not a spec change for the Java SE API.

I'll update the any copyright years as appropriate before pushing.

Thanks,

-Joe

--- old/src/java.base/share/classes/java/io/InputStream.java 2019-09-06 
11:11:22.330589001 -0700
+++ new/src/java.base/share/classes/java/io/InputStream.java 2019-09-06 
11:11:22.146589001 -0700
@@ -56,6 +56,11 @@
      private static final int DEFAULT_BUFFER_SIZE = 8192;

      /**
+     * Constructor for subclasses to call.
+     */
+    public InputStream() {}
+
+    /**
       * Returns a new {@code InputStream} that reads no bytes. The returned
       * stream is initially open.  The stream is closed by calling the
       * {@code close()} method.  Subsequent calls to {@code close()} 
have no
--- old/src/java.base/share/classes/java/io/ObjectInputStream.java 
2019-09-06 11:11:22.838589001 -0700
+++ new/src/java.base/share/classes/java/io/ObjectInputStream.java 
2019-09-06 11:11:22.646589001 -0700
@@ -1321,6 +1321,10 @@
       * Provide access to the persistent fields read from the input stream.
       */
      public abstract static class GetField {
+        /**
+         * Constructor for subclasses to call.
+         */
+        public GetField() {}

          /**
           * Get the ObjectStreamClass that describes the fields in the 
stream.
--- old/src/java.base/share/classes/java/io/ObjectOutputStream.java 
2019-09-06 11:11:23.346589001 -0700
+++ new/src/java.base/share/classes/java/io/ObjectOutputStream.java 
2019-09-06 11:11:23.162589001 -0700
@@ -879,6 +879,10 @@
       * @since 1.2
       */
      public abstract static class PutField {
+        /**
+         * Constructor for subclasses to call.
+         */
+        public PutField() {}

          /**
           * Put the value of the named boolean field into the 
persistent field.
--- old/src/java.base/share/classes/java/io/OutputStream.java 2019-09-06 
11:11:23.866589001 -0700
+++ new/src/java.base/share/classes/java/io/OutputStream.java 2019-09-06 
11:11:23.674589001 -0700
@@ -47,6 +47,11 @@
   */
  public abstract class OutputStream implements Closeable, Flushable {
      /**
+     * Constructor for subclasses to call.
+     */
+    public OutputStream() {}
+
+    /**
       * Returns a new {@code OutputStream} which discards all bytes.  The
       * returned stream is initially open.  The stream is closed by calling
       * the {@code close()} method.  Subsequent calls to {@code 
close()} have
--- 
old/src/java.base/share/classes/java/lang/InheritableThreadLocal.java 
2019-09-06 11:11:24.394589001 -0700
+++ 
new/src/java.base/share/classes/java/lang/InheritableThreadLocal.java 
2019-09-06 11:11:24.182589001 -0700
@@ -52,6 +52,11 @@

  public class InheritableThreadLocal<T> extends ThreadLocal<T> {
      /**
+     * Creates an inheritable thread local variable.
+     */
+    public InheritableThreadLocal() {}
+
+    /**
       * Computes the child's initial value for this inheritable 
thread-local
       * variable as a function of the parent's value at the time the child
       * thread is created.  This method is called from within the parent
--- old/src/java.base/share/classes/java/lang/LiveStackFrame.java 
2019-09-06 11:11:24.894589001 -0700
+++ new/src/java.base/share/classes/java/lang/LiveStackFrame.java 
2019-09-06 11:11:24.690589001 -0700
@@ -116,6 +116,11 @@
       */
      public abstract class PrimitiveSlot {
          /**
+         * Constructor.
+         */
+        PrimitiveSlot() {}
+
+        /**
           * Returns the size, in bytes, of the slot.
           */
          public abstract int size();
--- old/src/java.base/share/classes/java/lang/ThreadDeath.java 
2019-09-06 11:11:25.486589001 -0700
+++ new/src/java.base/share/classes/java/lang/ThreadDeath.java 
2019-09-06 11:11:25.234589001 -0700
@@ -49,4 +49,9 @@
  public class ThreadDeath extends Error {
      @java.io.Serial
      private static final long serialVersionUID = -4417128565033088268L;
+
+    /**
+     * Constructs a {@code ThreadDeath}.
+     */
+    public ThreadDeath() {}
  }
--- 
old/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java 
2019-09-06 11:11:26.150589001 -0700
+++ 
new/src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java 
2019-09-06 11:11:25.882589001 -0700
@@ -459,6 +459,11 @@
       */
      public class Factory {
          /**
+         * Construct a factory.
+         */
+        Factory() {}
+
+        /**
           * Get a concrete subclass of the top class for a given 
combination of bound types.
           *
           * @param speciesData the species requiring the class, not yet 
linked
--- 
old/src/java.base/share/classes/java/lang/invoke/ConstantBootstraps.java 
2019-09-06 11:11:26.846589001 -0700
+++ 
new/src/java.base/share/classes/java/lang/invoke/ConstantBootstraps.java 
2019-09-06 11:11:26.582589001 -0700
@@ -40,6 +40,12 @@
   * @since 11
   */
  public final class ConstantBootstraps {
+    /**
+     * Do not call.
+     */
+    @Deprecated(forRemoval=true, since="14")
+    public ConstantBootstraps() {}
+
      // implements the upcall from the JVM, 
MethodHandleNatives.linkDynamicConstant:
      /*non-public*/
      static Object makeConstant(MethodHandle bootstrapMethod,
--- old/src/java.base/share/classes/java/lang/reflect/Modifier.java 
2019-09-06 11:11:27.538589001 -0700
+++ new/src/java.base/share/classes/java/lang/reflect/Modifier.java 
2019-09-06 11:11:27.274589001 -0700
@@ -43,6 +43,12 @@
   * @since 1.1
   */
  public class Modifier {
+    /**
+     * Do not call.
+     */
+    @Deprecated(forRemoval=true, since="14")
+    public Modifier() {}
+

      /**
       * Return {@code true} if the integer argument includes the



More information about the core-libs-dev mailing list