8231314: java.time serialization warning cleanup
authorrriggs
Thu, 26 Sep 2019 11:10:19 -0400
changeset 58362 628c12967b02
parent 58361 ad863044567e
child 58363 cf7c6f013d6d
8231314: java.time serialization warning cleanup Reviewed-by: chegar, naoto, plevart
src/java.base/share/classes/java/time/Ser.java
src/java.base/share/classes/java/time/chrono/AbstractChronology.java
src/java.base/share/classes/java/time/chrono/Ser.java
src/java.base/share/classes/java/time/zone/Ser.java
--- a/src/java.base/share/classes/java/time/Ser.java	Thu Sep 26 07:20:51 2019 -0700
+++ b/src/java.base/share/classes/java/time/Ser.java	Thu Sep 26 11:10:19 2019 -0400
@@ -61,6 +61,7 @@
 import java.io.InvalidClassException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.io.StreamCorruptedException;
 
 /**
@@ -112,7 +113,7 @@
     /** The type being serialized. */
     private byte type;
     /** The object being serialized. */
-    private Object object;
+    private Serializable object;
 
     /**
      * Constructor for deserialization.
@@ -126,7 +127,7 @@
      * @param type  the type
      * @param object  the object
      */
-    Ser(byte type, Object object) {
+    Ser(byte type, Serializable object) {
         this.type = type;
         this.object = object;
     }
@@ -224,20 +225,35 @@
      * {@code Ser} object.
      *
      * <ul>
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.Duration">Duration</a> - {@code Duration.ofSeconds(seconds, nanos);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.Instant">Instant</a> - {@code Instant.ofEpochSecond(seconds, nanos);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDate">LocalDate</a> - {@code LocalDate.of(year, month, day);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDateTime">LocalDateTime</a> - {@code LocalDateTime.of(date, time);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalTime">LocalTime</a> - {@code LocalTime.of(hour, minute, second, nano);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.MonthDay">MonthDay</a> - {@code MonthDay.of(month, day);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetTime">OffsetTime</a> - {@code OffsetTime.of(time, offset);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetDateTime">OffsetDateTime</a> - {@code OffsetDateTime.of(dateTime, offset);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.Period">Period</a> - {@code Period.of(years, months, days);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.Year">Year</a> - {@code Year.of(year);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.YearMonth">YearMonth</a> - {@code YearMonth.of(year, month);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZonedDateTime">ZonedDateTime</a> - {@code ZonedDateTime.ofLenient(dateTime, offset, zone);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneId">ZoneId</a> - {@code ZoneId.of(id);}
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneOffset">ZoneOffset</a> - {@code (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900));}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.Duration">Duration</a> -
+     *          {@code Duration.ofSeconds(seconds, nanos);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.Instant">Instant</a> -
+     *          {@code Instant.ofEpochSecond(seconds, nanos);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDate">LocalDate</a> -
+     *          {@code LocalDate.of(year, month, day);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalDateTime">LocalDateTime</a> -
+     *          {@code LocalDateTime.of(date, time);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.LocalTime">LocalTime</a> -
+     *          {@code LocalTime.of(hour, minute, second, nano);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.MonthDay">MonthDay</a> -
+     *          {@code MonthDay.of(month, day);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetTime">OffsetTime</a> -
+     *          {@code OffsetTime.of(time, offset);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.OffsetDateTime">OffsetDateTime</a> -
+     *          {@code OffsetDateTime.of(dateTime, offset);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.Period">Period</a> -
+     *          {@code Period.of(years, months, days);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.Year">Year</a> -
+     *          {@code Year.of(year);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.YearMonth">YearMonth</a> -
+     *          {@code YearMonth.of(year, month);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZonedDateTime">ZonedDateTime</a> -
+     *          {@code ZonedDateTime.ofLenient(dateTime, offset, zone);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneId">ZoneId</a> -
+     *          {@code ZoneId.of(id);}
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.ZoneOffset">ZoneOffset</a> -
+     *          {@code (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) :
+     *          ZoneOffset.ofTotalSeconds(offsetByte * 900));}
      * </ul>
      *
      * @param in  the data to read, not null
@@ -247,12 +263,13 @@
         object = readInternal(type, in);
     }
 
-    static Object read(ObjectInput in) throws IOException, ClassNotFoundException {
+    static Serializable read(ObjectInput in) throws IOException, ClassNotFoundException {
         byte type = in.readByte();
         return readInternal(type, in);
     }
 
-    private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
+    private static Serializable readInternal(byte type, ObjectInput in)
+            throws IOException, ClassNotFoundException {
         switch (type) {
             case DURATION_TYPE: return Duration.readExternal(in);
             case INSTANT_TYPE: return Instant.readExternal(in);
--- a/src/java.base/share/classes/java/time/chrono/AbstractChronology.java	Thu Sep 26 07:20:51 2019 -0700
+++ b/src/java.base/share/classes/java/time/chrono/AbstractChronology.java	Thu Sep 26 11:10:19 2019 -0400
@@ -731,7 +731,7 @@
      */
     @java.io.Serial
     Object writeReplace() {
-        return new Ser(Ser.CHRONO_TYPE, this);
+        return new Ser(Ser.CHRONO_TYPE, (Serializable)this);
     }
 
     /**
--- a/src/java.base/share/classes/java/time/chrono/Ser.java	Thu Sep 26 07:20:51 2019 -0700
+++ b/src/java.base/share/classes/java/time/chrono/Ser.java	Thu Sep 26 11:10:19 2019 -0400
@@ -61,6 +61,7 @@
 import java.io.InvalidClassException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.io.StreamCorruptedException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -110,7 +111,7 @@
     /** The type being serialized. */
     private byte type;
     /** The object being serialized. */
-    private Object object;
+    private Serializable object;
 
     /**
      * Constructor for deserialization.
@@ -124,7 +125,7 @@
      * @param type  the type
      * @param object  the object
      */
-    Ser(byte type, Object object) {
+    Ser(byte type, Serializable object) {
         this.type = type;
         this.object = object;
     }
@@ -203,18 +204,30 @@
      * {@code Ser} object.
      *
      * <ul>
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahChronology">HijrahChronology</a> - Chronology.of(id)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.IsoChronology">IsoChronology</a> - Chronology.of(id)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseChronology">JapaneseChronology</a> - Chronology.of(id)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoChronology">MinguoChronology</a> - Chronology.of(id)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistChronology">ThaiBuddhistChronology</a> - Chronology.of(id)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoLocalDateTimeImpl">ChronoLocalDateTime</a> - date.atTime(time)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoZonedDateTimeImpl">ChronoZonedDateTime</a> - dateTime.atZone(offset).withZoneSameLocal(zone)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseDate">JapaneseDate</a> - JapaneseChronology.INSTANCE.date(year, month, dayOfMonth)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseEra">JapaneseEra</a> - JapaneseEra.of(eraValue)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahDate">HijrahDate</a> - HijrahChronology chrono.date(year, month, dayOfMonth)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoDate">MinguoDate</a> - MinguoChronology.INSTANCE.date(year, month, dayOfMonth)
-     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistDate">ThaiBuddhistDate</a> - ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahChronology">HijrahChronology</a> -
+     *          Chronology.of(id)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.IsoChronology">IsoChronology</a> -
+     *          Chronology.of(id)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseChronology">JapaneseChronology</a> -
+     *          Chronology.of(id)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoChronology">MinguoChronology</a> -
+     *          Chronology.of(id)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistChronology">ThaiBuddhistChronology</a> -
+     *          Chronology.of(id)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoLocalDateTimeImpl">ChronoLocalDateTime</a> -
+     *          date.atTime(time)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ChronoZonedDateTimeImpl">ChronoZonedDateTime</a> -
+     *          dateTime.atZone(offset).withZoneSameLocal(zone)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseDate">JapaneseDate</a> -
+     *          JapaneseChronology.INSTANCE.date(year, month, dayOfMonth)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.JapaneseEra">JapaneseEra</a> -
+     *          JapaneseEra.of(eraValue)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.HijrahDate">HijrahDate</a> -
+     *          HijrahChronology chrono.date(year, month, dayOfMonth)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.MinguoDate">MinguoDate</a> -
+     *          MinguoChronology.INSTANCE.date(year, month, dayOfMonth)
+     * <li><a href="{@docRoot}/serialized-form.html#java.time.chrono.ThaiBuddhistDate">ThaiBuddhistDate</a> -
+     *          ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth)
      * </ul>
      *
      * @param in  the data stream to read from, not null
@@ -225,16 +238,17 @@
         object = readInternal(type, in);
     }
 
-    static Object read(ObjectInput in) throws IOException, ClassNotFoundException {
+    static Serializable read(ObjectInput in) throws IOException, ClassNotFoundException {
         byte type = in.readByte();
         return readInternal(type, in);
     }
 
-    private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
+    private static Serializable readInternal(byte type, ObjectInput in)
+            throws IOException, ClassNotFoundException {
         switch (type) {
-            case CHRONO_TYPE: return AbstractChronology.readExternal(in);
-            case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in);
-            case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in);
+            case CHRONO_TYPE: return (Serializable)AbstractChronology.readExternal(in);
+            case CHRONO_LOCAL_DATE_TIME_TYPE: return (Serializable)ChronoLocalDateTimeImpl.readExternal(in);
+            case CHRONO_ZONE_DATE_TIME_TYPE: return (Serializable)ChronoZonedDateTimeImpl.readExternal(in);
             case JAPANESE_DATE_TYPE:  return JapaneseDate.readExternal(in);
             case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in);
             case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in);
--- a/src/java.base/share/classes/java/time/zone/Ser.java	Thu Sep 26 07:20:51 2019 -0700
+++ b/src/java.base/share/classes/java/time/zone/Ser.java	Thu Sep 26 11:10:19 2019 -0400
@@ -68,6 +68,7 @@
 import java.io.InvalidClassException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.io.StreamCorruptedException;
 import java.time.ZoneOffset;
 
@@ -97,7 +98,7 @@
     /** The type being serialized. */
     private byte type;
     /** The object being serialized. */
-    private Object object;
+    private Serializable object;
 
     /**
      * Constructor for deserialization.
@@ -111,7 +112,7 @@
      * @param type  the type
      * @param object  the object
      */
-    Ser(byte type, Object object) {
+    Ser(byte type, Serializable object) {
         this.type = type;
         this.object = object;
     }
@@ -183,12 +184,13 @@
         object = readInternal(type, in);
     }
 
-    static Object read(DataInput in) throws IOException, ClassNotFoundException {
+    static Serializable read(DataInput in) throws IOException, ClassNotFoundException {
         byte type = in.readByte();
         return readInternal(type, in);
     }
 
-    private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException {
+    private static Serializable readInternal(byte type, DataInput in)
+            throws IOException, ClassNotFoundException {
         switch (type) {
             case ZRULES:
                 return ZoneRules.readExternal(in);