diff --git a/src/share/classes/java/time/Duration.java b/src/share/classes/java/time/Duration.java index ab7da66f83a63f9c0d536183e999f93fe0836817..ce2ba7781b058a12d0f1b139e2a82fb3276e5a2a 100644 --- a/src/share/classes/java/time/Duration.java +++ b/src/share/classes/java/time/Duration.java @@ -74,7 +74,7 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.io.InvalidObjectException; -import java.io.ObjectStreamException; +import java.io.InvalidObjectException; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; @@ -1299,8 +1299,9 @@ public final class Duration /** * Writes the object using a * dedicated serialized form. + * @serialData *
- * out.writeByte(1); // identifies this as a Duration
+ * out.writeByte(1); // identifies a Duration
* out.writeLong(seconds);
* out.writeInt(nanos);
*
@@ -1316,7 +1317,7 @@ public final class Duration
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/Instant.java b/src/share/classes/java/time/Instant.java
index aeecdbed5247becb2137b6e6e3f3603425d3bd29..9d74e29f91ae228b5e1579d12c10e2a018ba952d 100644
--- a/src/share/classes/java/time/Instant.java
+++ b/src/share/classes/java/time/Instant.java
@@ -76,7 +76,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@@ -1317,8 +1317,9 @@ public final class Instant
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(2); // identifies this as an Instant
+ * out.writeByte(2); // identifies an Instant
* out.writeLong(seconds);
* out.writeInt(nanos);
*
@@ -1334,7 +1335,7 @@ public final class Instant
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/LocalDate.java b/src/share/classes/java/time/LocalDate.java
index d96f5b1fd1e9fc1606663dd960b4ddb6cd7f84a0..3005658366a2b7f4b03b67393002e5b8966ab87b 100644
--- a/src/share/classes/java/time/LocalDate.java
+++ b/src/share/classes/java/time/LocalDate.java
@@ -78,7 +78,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Era;
@@ -2019,8 +2019,9 @@ public final class LocalDate
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(3); // identifies this as a LocalDate
+ * out.writeByte(3); // identifies a LocalDate
* out.writeInt(year);
* out.writeByte(month);
* out.writeByte(day);
@@ -2037,7 +2038,7 @@ public final class LocalDate
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/LocalDateTime.java b/src/share/classes/java/time/LocalDateTime.java
index d68d6f52537d9b517a0e1f419c3bd4edb8ee95fd..de8b246d6bb3a63db1da03946211e4dedaa35829 100644
--- a/src/share/classes/java/time/LocalDateTime.java
+++ b/src/share/classes/java/time/LocalDateTime.java
@@ -76,7 +76,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.ChronoLocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -1953,8 +1953,9 @@ public final class LocalDateTime
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(5); // identifies this as a LocalDateTime
+ * out.writeByte(5); // identifies a LocalDateTime
* // the date excluding the one byte header
* // the time excluding the one byte header
*
@@ -1970,7 +1971,7 @@ public final class LocalDateTime
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/LocalTime.java b/src/share/classes/java/time/LocalTime.java
index 2bace6e7bc9047f36b3da4d61ac818c83ffa53da..a6270db19cfd026fcc82da2b6561174143ae1cf0 100644
--- a/src/share/classes/java/time/LocalTime.java
+++ b/src/share/classes/java/time/LocalTime.java
@@ -74,7 +74,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@@ -1595,8 +1595,11 @@ public final class LocalTime
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
+ * A twos-complement value indicates the remaining values are not in the stream
+ * and should be set to zero.
*
- * out.writeByte(4); // identifies this as a LocalTime
+ * out.writeByte(4); // identifies a LocalTime
* if (nano == 0) {
* if (second == 0) {
* if (minute == 0) {
@@ -1629,7 +1632,7 @@ public final class LocalTime
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/MonthDay.java b/src/share/classes/java/time/MonthDay.java
index 06aa0437af8a94acf16640129a34f4cb997fae6a..22807822f2bec47c6e2825a71abae497718bdc73 100644
--- a/src/share/classes/java/time/MonthDay.java
+++ b/src/share/classes/java/time/MonthDay.java
@@ -68,7 +68,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
@@ -744,9 +744,10 @@ public final class MonthDay
//-----------------------------------------------------------------------
/**
* Writes the object using a
- * dedicated serialized form.
+ * dedicated serialized form.
+ * @serialData
*
- * out.writeByte(13); // identifies this as a MonthDay
+ * out.writeByte(13); // identifies a MonthDay
* out.writeByte(month);
* out.writeByte(day);
*
@@ -762,7 +763,7 @@ public final class MonthDay
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/OffsetDateTime.java b/src/share/classes/java/time/OffsetDateTime.java
index 5641154cf3ec44560fac4f311fc5d34fc49dae9d..f894e53e46f0d36cd5673648418056b7fefc8ae1 100644
--- a/src/share/classes/java/time/OffsetDateTime.java
+++ b/src/share/classes/java/time/OffsetDateTime.java
@@ -72,7 +72,7 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
@@ -1901,9 +1901,10 @@ public final class OffsetDateTime
//-----------------------------------------------------------------------
/**
* Writes the object using a
- * dedicated serialized form.
+ * dedicated serialized form.
+ * @serialData
*
- * out.writeByte(10); // identifies this as a OffsetDateTime
+ * out.writeByte(10); // identifies a OffsetDateTime
* out.writeObject(dateTime);
* out.writeObject(offset);
*
@@ -1919,7 +1920,7 @@ public final class OffsetDateTime
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/OffsetTime.java b/src/share/classes/java/time/OffsetTime.java
index 2872cff4b265aae3d7d4d6adbece3169d4cc57de..6c67ef82bb1168996eb83e031308f77aed5dffe4 100644
--- a/src/share/classes/java/time/OffsetTime.java
+++ b/src/share/classes/java/time/OffsetTime.java
@@ -73,7 +73,7 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@@ -1372,9 +1372,10 @@ public final class OffsetTime
//-----------------------------------------------------------------------
/**
* Writes the object using a
- * dedicated serialized form.
+ * dedicated serialized form.
+ * @serialData
*
- * out.writeByte(9); // identifies this as a OffsetTime
+ * out.writeByte(9); // identifies a OffsetTime
* out.writeObject(time);
* out.writeObject(offset);
*
@@ -1390,7 +1391,7 @@ public final class OffsetTime
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/Period.java b/src/share/classes/java/time/Period.java
index 45980d08740a4ee260d67adce2cf8a1a2dd1689f..161ce49e56589c3602fc0306bb3e54a703938c09 100644
--- a/src/share/classes/java/time/Period.java
+++ b/src/share/classes/java/time/Period.java
@@ -70,7 +70,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Chronology;
@@ -993,11 +993,12 @@ public final class Period
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(14); // identifies this as a Period
+ * out.writeByte(14); // identifies a Period
* out.writeInt(years);
* out.writeInt(months);
- * out.writeInt(seconds);
+ * out.writeInt(days);
*
*
* @return the instance of {@code Ser}, not null
@@ -1011,7 +1012,7 @@ public final class Period
* @return never
* @throws java.io.InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/Ser.java b/src/share/classes/java/time/Ser.java
index 607198952c195a15d520473ac0358b062f7c03e8..885b43abd83a872b3c4d6ce852aba53a8c39c744 100644
--- a/src/share/classes/java/time/Ser.java
+++ b/src/share/classes/java/time/Ser.java
@@ -72,14 +72,14 @@ import java.io.StreamCorruptedException;
* byte flag would be used in order to specify an alternative version of the type format.
* For example {@code LOCAL_DATE_TYPE_VERSION_2 = 21}.
*
- * In order to serialise the object it writes its byte and then calls back to the appropriate class where
- * the serialisation is performed. In order to deserialise the object it read in the type byte, switching
+ * In order to serialize the object it writes its byte and then calls back to the appropriate class where
+ * the serialization is performed. In order to deserialize the object it read in the type byte, switching
* in order to select which class to call back into.
*
- * The serialisation format is determined on a per class basis. In the case of field based classes each
+ * The serialization format is determined on a per class basis. In the case of field based classes each
* of the fields is written out with an appropriate size format in descending order of the field's size. For
* example in the case of {@link LocalDate} year is written before month. Composite classes, such as
- * {@link LocalDateTime} are serialised as one object.
+ * {@link LocalDateTime} are serialized as one object.
*
* This class is mutable and should be created once per serialization.
*
@@ -133,6 +133,27 @@ final class Ser implements Externalizable {
//-----------------------------------------------------------------------
/**
* Implements the {@code Externalizable} interface to write the object.
+ * @serialData
+ *
+ * Each serializable class is mapped to a type that is the first byte
+ * in the stream. Refer to each class {@code writeReplace}
+ * serialized form for the value of the type and sequence of values for the type.
+ *
- * out.writeByte(11); // identifies this as a Year
+ * out.writeByte(11); // identifies a Year
* out.writeInt(year);
*
*
@@ -1097,7 +1098,7 @@ public final class Year
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/YearMonth.java b/src/share/classes/java/time/YearMonth.java
index 1d974095336124d6c9e1daf949d573a102cbe652..541676117eba836d35953451e13540b88a217e4b 100644
--- a/src/share/classes/java/time/YearMonth.java
+++ b/src/share/classes/java/time/YearMonth.java
@@ -77,7 +77,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
@@ -1205,9 +1205,10 @@ public final class YearMonth
//-----------------------------------------------------------------------
/**
* Writes the object using a
- * dedicated serialized form.
+ * dedicated serialized form.
+ * @serialData
*
- * out.writeByte(12); // identifies this as a YearMonth
+ * out.writeByte(12); // identifies a YearMonth
* out.writeInt(year);
* out.writeByte(month);
*
@@ -1223,7 +1224,7 @@ public final class YearMonth
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/ZoneId.java b/src/share/classes/java/time/ZoneId.java
index dcde85ae884b9f9fb14d16a3d4845f30882663eb..86b0c74fd9df40bed650f20e2cd44dca0ca0891c 100644
--- a/src/share/classes/java/time/ZoneId.java
+++ b/src/share/classes/java/time/ZoneId.java
@@ -63,6 +63,7 @@ package java.time;
import java.io.DataOutput;
import java.io.IOException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
@@ -661,6 +662,15 @@ public abstract class ZoneId implements Serializable {
}
//-----------------------------------------------------------------------
+ /**
+ * Defend against malicious streams.
+ * @return never
+ * @throws InvalidObjectException always
+ */
+ private Object readResolve() throws InvalidObjectException {
+ throw new InvalidObjectException("Deserialization via serialization delegate");
+ }
+
/**
* Outputs this zone as a {@code String}, using the ID.
*
@@ -675,9 +685,10 @@ public abstract class ZoneId implements Serializable {
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(7); // identifies this as a ZoneId (not ZoneOffset)
- * out.writeUTF(zoneId);
+ * out.writeByte(7); // identifies a ZoneId (not ZoneOffset)
+ * out.writeUTF(getId());
*
* * When read back in, the {@code ZoneId} will be created as though using diff --git a/src/share/classes/java/time/ZoneOffset.java b/src/share/classes/java/time/ZoneOffset.java index c5e4d056ee82528891af0051ee390fc64448ac90..2d63a978d8cd448ee1bd1b60fc5c5da5cbbf11a2 100644 --- a/src/share/classes/java/time/ZoneOffset.java +++ b/src/share/classes/java/time/ZoneOffset.java @@ -70,7 +70,7 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.io.InvalidObjectException; -import java.io.ObjectStreamException; +import java.io.InvalidObjectException; import java.io.Serializable; import java.time.temporal.ChronoField; import java.time.temporal.Temporal; @@ -740,12 +740,13 @@ public final class ZoneOffset /** * Writes the object using a * dedicated serialized form. + * @serialData *
- * out.writeByte(8); // identifies this as a ZoneOffset
+ * out.writeByte(8); // identifies a ZoneOffset
* int offsetByte = totalSeconds % 900 == 0 ? totalSeconds / 900 : 127;
* out.writeByte(offsetByte);
* if (offsetByte == 127) {
- * out.writeInt(totalSeconds);
+ * out.writeInt(totalSeconds);
* }
*
*
@@ -760,7 +761,7 @@ public final class ZoneOffset
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/ZoneRegion.java b/src/share/classes/java/time/ZoneRegion.java
index 66d30709d98a75ffa7084246326cb3124f271782..31669d79c0323ceade6335a84ec681ab22361dbf 100644
--- a/src/share/classes/java/time/ZoneRegion.java
+++ b/src/share/classes/java/time/ZoneRegion.java
@@ -60,7 +60,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.zone.ZoneRules;
import java.time.zone.ZoneRulesException;
@@ -181,8 +181,9 @@ final class ZoneRegion extends ZoneId implements Serializable {
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(7); // identifies this as a ZoneId (not ZoneOffset)
+ * out.writeByte(7); // identifies a ZoneId (not ZoneOffset)
* out.writeUTF(zoneId);
*
*
@@ -197,7 +198,7 @@ final class ZoneRegion extends ZoneId implements Serializable {
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/ZonedDateTime.java b/src/share/classes/java/time/ZonedDateTime.java
index 151470ecf939903b5c480ea9a01692988867e3ee..251ca888a1412e96e2bb6192f5bd07343002f327 100644
--- a/src/share/classes/java/time/ZonedDateTime.java
+++ b/src/share/classes/java/time/ZonedDateTime.java
@@ -69,7 +69,7 @@ import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInput;
-import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.ChronoZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -2192,9 +2192,10 @@ public final class ZonedDateTime
/**
* Writes the object using a
* dedicated serialized form.
+ * @serialData
*
- * out.writeByte(6); // identifies this as a ZonedDateTime
- * // the date-time excluding the one byte header
+ * out.writeByte(6); // identifies a ZonedDateTime
+ * // the dateTime excluding the one byte header
* // the offset excluding the one byte header
* // the zone ID excluding the one byte header
*
@@ -2210,7 +2211,7 @@ public final class ZonedDateTime
* @return never
* @throws InvalidObjectException always
*/
- private Object readResolve() throws ObjectStreamException {
+ private Object readResolve() throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
diff --git a/src/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java b/src/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java
index 14f7bd927c232b5b62f55fd4910b23a0b799336e..cd7f04e47987d754c2ccc1a67b524569c0330faa 100644
--- a/src/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java
+++ b/src/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java
@@ -94,7 +94,7 @@ import java.util.Objects;
*
* @implSpec
* This class is immutable and thread-safe.
- *
+ * @serial
* @param + * out.writeByte(2); // identifies a ChronoLocalDateTime + * out.writeObject(toLocalDate()); + * out.witeObject(toLocalTime()); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.CHRONO_LOCAL_DATE_TIME_TYPE, this); } @@ -411,7 +423,7 @@ final class ChronoLocalDateTimeImpl
+ * out.writeByte(3); // identifies a ChronoZonedDateTime + * out.writeObject(toLocalDateTime()); + * out.writeObject(getOffset()); + * out.writeObject(getZone()); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.CHRONO_ZONE_DATE_TIME_TYPE, this); } @@ -330,7 +347,7 @@ final class ChronoZonedDateTimeImpl
- * out.writeByte(1); // identifies this as a Chronology
+ * out.writeByte(1); // identifies a Chronology
* out.writeUTF(getId());
*
*
* @return the instance of {@code Ser}, not null
*/
- protected Object writeReplace() {
+ Object writeReplace() {
return new Ser(Ser.CHRONO_TYPE, this);
}
@@ -1274,14 +1275,26 @@ public abstract class Chronology implements Comparable+ * out.writeByte(1); // identifies a Chronology + * out.writeUTF(getId()); + *+ * + * @return the instance of {@code Ser}, not null + */ + @Override + Object writeReplace() { + return super.writeReplace(); + } + + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } } diff --git a/src/share/classes/java/time/chrono/HijrahDate.java b/src/share/classes/java/time/chrono/HijrahDate.java index ef40b6dc94839ddd762a14db7802bab1e891ae4b..8e385c9470b0608ba1134fe80e8a3b1c74730a73 100644 --- a/src/share/classes/java/time/chrono/HijrahDate.java +++ b/src/share/classes/java/time/chrono/HijrahDate.java @@ -65,6 +65,7 @@ import static java.time.temporal.ChronoField.MONTH_OF_YEAR; import static java.time.temporal.ChronoField.YEAR; import java.io.IOException; +import java.io.InvalidObjectException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.Serializable; @@ -118,7 +119,7 @@ public final class HijrahDate /** * The Chronology of this HijrahDate. */ - private final HijrahChronology chrono; + private final transient HijrahChronology chrono; /** * The proleptic year. */ @@ -600,29 +601,41 @@ public final class HijrahDate } //----------------------------------------------------------------------- + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } + + /** + * Writes the object using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(6); // identifies a HijrahDate + * out.writeObject(chrono); // the HijrahChronology variant + * out.writeInt(get(YEAR)); + * out.writeByte(get(MONTH_OF_YEAR)); + * out.writeByte(get(DAY_OF_MONTH)); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.HIJRAH_DATE_TYPE, this); } void writeExternal(ObjectOutput out) throws IOException { // HijrahChronology is implicit in the Hijrah_DATE_TYPE - out.writeObject(chrono); + out.writeObject(getChronology()); out.writeInt(get(YEAR)); out.writeByte(get(MONTH_OF_YEAR)); out.writeByte(get(DAY_OF_MONTH)); } - /** - * Replaces the date instance from the stream with a valid one. - * ReadExternal has already read the fields and created a new instance - * from the data. - * - * @return the resolved date, never null - */ - private Object readResolve() { - return this; - } - static HijrahDate readExternal(ObjectInput in) throws IOException, ClassNotFoundException { HijrahChronology chrono = (HijrahChronology) in.readObject(); int year = in.readInt(); diff --git a/src/share/classes/java/time/chrono/HijrahEra.java b/src/share/classes/java/time/chrono/HijrahEra.java index 1e99d6062ab3af65dbe83c6de67253e19842ddba..4390f698c32ee2dd3907e70d76ac91ee084a0928 100644 --- a/src/share/classes/java/time/chrono/HijrahEra.java +++ b/src/share/classes/java/time/chrono/HijrahEra.java @@ -63,9 +63,6 @@ package java.time.chrono; import static java.time.temporal.ChronoField.ERA; -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; import java.time.DateTimeException; import java.time.temporal.ChronoField; import java.time.temporal.TemporalField; @@ -158,18 +155,4 @@ public enum HijrahEra implements Era { return Era.super.range(field); } - //----------------------------------------------------------------------- - private Object writeReplace() { - return new Ser(Ser.HIJRAH_ERA_TYPE, this); - } - - void writeExternal(DataOutput out) throws IOException { - out.writeByte(this.getValue()); - } - - static HijrahEra readExternal(DataInput in) throws IOException { - byte eraValue = in.readByte(); - return HijrahEra.of(eraValue); - } - } diff --git a/src/share/classes/java/time/chrono/IsoChronology.java b/src/share/classes/java/time/chrono/IsoChronology.java index a2f6badeaa524b544cc6ab749debd1965a077ffa..2012e64e04d6eb560889f679f3cf0f9ce8edc0be 100644 --- a/src/share/classes/java/time/chrono/IsoChronology.java +++ b/src/share/classes/java/time/chrono/IsoChronology.java @@ -61,6 +61,8 @@ */ package java.time.chrono; +import java.io.InvalidObjectException; +import java.io.ObjectStreamException; import static java.time.temporal.ChronoField.DAY_OF_MONTH; import static java.time.temporal.ChronoField.ERA; import static java.time.temporal.ChronoField.MONTH_OF_YEAR; @@ -563,4 +565,29 @@ public final class IsoChronology extends Chronology implements Serializable { return field.range(); } + //----------------------------------------------------------------------- + /** + * Writes the Chronology using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(1); // identifies a Chronology + * out.writeUTF(getId()); + *+ * + * @return the instance of {@code Ser}, not null + */ + @Override + Object writeReplace() { + return super.writeReplace(); + } + + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } } diff --git a/src/share/classes/java/time/chrono/JapaneseChronology.java b/src/share/classes/java/time/chrono/JapaneseChronology.java index 68a12755ea30aff50caf2ebb73018417f53e3de3..b01707e63ab96260d588301eefd640811cf64634 100644 --- a/src/share/classes/java/time/chrono/JapaneseChronology.java +++ b/src/share/classes/java/time/chrono/JapaneseChronology.java @@ -56,6 +56,8 @@ */ package java.time.chrono; +import java.io.InvalidObjectException; +import java.io.ObjectStreamException; import static java.time.temporal.ChronoField.DAY_OF_MONTH; import static java.time.temporal.ChronoField.DAY_OF_YEAR; import static java.time.temporal.ChronoField.ERA; @@ -503,4 +505,29 @@ public final class JapaneseChronology extends Chronology implements Serializable return dateYearDay(era, yoe, doy); // smart is same as strict } + //----------------------------------------------------------------------- + /** + * Writes the Chronology using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(1); // identifies a Chronology + * out.writeUTF(getId()); + *+ * + * @return the instance of {@code Ser}, not null + */ + @Override + Object writeReplace() { + return super.writeReplace(); + } + + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } } diff --git a/src/share/classes/java/time/chrono/JapaneseDate.java b/src/share/classes/java/time/chrono/JapaneseDate.java index e49a8f33c75533af25fb0127a5ce63a660c2c757..24ad7a921c0a673a1f50e8111ad7fe1cb746a998 100644 --- a/src/share/classes/java/time/chrono/JapaneseDate.java +++ b/src/share/classes/java/time/chrono/JapaneseDate.java @@ -69,6 +69,7 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.io.InvalidObjectException; import java.io.Serializable; import java.time.Clock; import java.time.DateTimeException; @@ -129,7 +130,7 @@ public final class JapaneseDate /** * The underlying ISO local date. */ - private transient final LocalDate isoDate; + private final transient LocalDate isoDate; /** * The JapaneseEra of this date. */ @@ -689,6 +690,28 @@ public final class JapaneseDate } //----------------------------------------------------------------------- + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } + + /** + * Writes the object using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(4); // identifies a JapaneseDate + * out.writeInt(get(YEAR)); + * out.writeByte(get(MONTH_OF_YEAR)); + * out.writeByte(get(DAY_OF_MONTH)); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.JAPANESE_DATE_TYPE, this); } diff --git a/src/share/classes/java/time/chrono/JapaneseEra.java b/src/share/classes/java/time/chrono/JapaneseEra.java index 29dda6bbbcfb696c2a9376e186db9244cae0dfbd..46eee0b59f85fcccf0f3e5c8ef40846ea4bae994 100644 --- a/src/share/classes/java/time/chrono/JapaneseEra.java +++ b/src/share/classes/java/time/chrono/JapaneseEra.java @@ -155,7 +155,7 @@ public final class JapaneseEra * The era value. * @serial */ - private final int eraValue; + private final transient int eraValue; // the first day of the era private final transient LocalDate since; @@ -371,6 +371,17 @@ public final class JapaneseEra } //----------------------------------------------------------------------- + /** + * Writes the object using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(5); // identifies a JapaneseEra + * out.writeInt(getValue()); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.JAPANESE_ERA_TYPE, this); } diff --git a/src/share/classes/java/time/chrono/MinguoChronology.java b/src/share/classes/java/time/chrono/MinguoChronology.java index 088588004c30053885ac15d2c0f137cf03ad3be2..db75a8645d6a5893b4c8e7291d2be65df9aa99e5 100644 --- a/src/share/classes/java/time/chrono/MinguoChronology.java +++ b/src/share/classes/java/time/chrono/MinguoChronology.java @@ -56,6 +56,8 @@ */ package java.time.chrono; +import java.io.InvalidObjectException; +import java.io.ObjectStreamException; import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; import static java.time.temporal.ChronoField.YEAR; @@ -333,4 +335,29 @@ public final class MinguoChronology extends Chronology implements Serializable { return (MinguoDate) super.resolveDate(fieldValues, resolverStyle); } + //----------------------------------------------------------------------- + /** + * Writes the Chronology using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(1); // identifies a Chronology + * out.writeUTF(getId()); + *+ * + * @return the instance of {@code Ser}, not null + */ + @Override + Object writeReplace() { + return super.writeReplace(); + } + + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } } diff --git a/src/share/classes/java/time/chrono/MinguoDate.java b/src/share/classes/java/time/chrono/MinguoDate.java index e15b0e90a15419c10c5876e3c4dce1dc73ddf3b4..16585e7e99217caa03c6f2cff550447983823c14 100644 --- a/src/share/classes/java/time/chrono/MinguoDate.java +++ b/src/share/classes/java/time/chrono/MinguoDate.java @@ -64,6 +64,7 @@ import static java.time.temporal.ChronoField.YEAR; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.io.InvalidObjectException; import java.io.Serializable; import java.time.Clock; import java.time.DateTimeException; @@ -106,7 +107,7 @@ public final class MinguoDate /** * The underlying date. */ - private final LocalDate isoDate; + private final transient LocalDate isoDate; //----------------------------------------------------------------------- /** @@ -448,6 +449,28 @@ public final class MinguoDate } //----------------------------------------------------------------------- + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } + + /** + * Writes the object using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(8); // identifies a MinguoDate + * out.writeInt(get(YEAR)); + * out.writeByte(get(MONTH_OF_YEAR)); + * out.writeByte(get(DAY_OF_MONTH)); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.MINGUO_DATE_TYPE, this); } diff --git a/src/share/classes/java/time/chrono/MinguoEra.java b/src/share/classes/java/time/chrono/MinguoEra.java index edf1ad5610aed95e0040a7dde25f1877c2efe5a5..6bfdab2551d372d24fe78b7fe600b54e71ac4a69 100644 --- a/src/share/classes/java/time/chrono/MinguoEra.java +++ b/src/share/classes/java/time/chrono/MinguoEra.java @@ -61,9 +61,6 @@ */ package java.time.chrono; -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; import java.time.DateTimeException; /** @@ -155,18 +152,4 @@ public enum MinguoEra implements Era { return ordinal(); } - //----------------------------------------------------------------------- - private Object writeReplace() { - return new Ser(Ser.MINGUO_ERA_TYPE, this); - } - - void writeExternal(DataOutput out) throws IOException { - out.writeByte(this.getValue()); - } - - static MinguoEra readExternal(DataInput in) throws IOException { - byte eraValue = in.readByte(); - return MinguoEra.of(eraValue); - } - } diff --git a/src/share/classes/java/time/chrono/Ser.java b/src/share/classes/java/time/chrono/Ser.java index ff59aec4190910c24bef0bd9fb254e0f33540790..cc99f481f8c45e5ade7b9827d36be7e7aa812f09 100644 --- a/src/share/classes/java/time/chrono/Ser.java +++ b/src/share/classes/java/time/chrono/Ser.java @@ -74,14 +74,14 @@ import java.time.LocalDateTime; * byte flag would be used in order to specify an alternative version of the type format. * For example {@code CHRONO_TYPE_VERSION_2 = 21} *
- * In order to serialise the object it writes its byte and then calls back to the appropriate class where - * the serialisation is performed. In order to deserialise the object it read in the type byte, switching + * In order to serialize the object it writes its byte and then calls back to the appropriate class where + * the serialization is performed. In order to deserialize the object it read in the type byte, switching * in order to select which class to call back into. *
- * The serialisation format is determined on a per class basis. In the case of field based classes each + * The serialization format is determined on a per class basis. In the case of field based classes each * of the fields is written out with an appropriate size format in descending order of the field's size. For * example in the case of {@link LocalDate} year is written before month. Composite classes, such as - * {@link LocalDateTime} are serialised as one object. Enum classes are serialised using the index of their + * {@link LocalDateTime} are serialized as one object. Enum classes are serialized using the index of their * element. *
* This class is mutable and should be created once per serialization. @@ -102,11 +102,8 @@ final class Ser implements Externalizable { static final byte JAPANESE_DATE_TYPE = 4; static final byte JAPANESE_ERA_TYPE = 5; static final byte HIJRAH_DATE_TYPE = 6; - static final byte HIJRAH_ERA_TYPE = 7; - static final byte MINGUO_DATE_TYPE = 8; - static final byte MINGUO_ERA_TYPE = 9; - static final byte THAIBUDDHIST_DATE_TYPE = 10; - static final byte THAIBUDDHIST_ERA_TYPE = 11; + static final byte MINGUO_DATE_TYPE = 7; + static final byte THAIBUDDHIST_DATE_TYPE = 8; /** The type being serialized. */ private byte type; @@ -133,6 +130,24 @@ final class Ser implements Externalizable { //----------------------------------------------------------------------- /** * Implements the {@code Externalizable} interface to write the object. + * @serialData + * Each serializable class is mapped to a type that is the first byte + * in the stream. Refer to each class {@code writeReplace} + * serialized form for the value of the type and sequence of values for the type. + *
+ * out.writeByte(1); // identifies a Chronology + * out.writeUTF(getId()); + *+ * + * @return the instance of {@code Ser}, not null + */ + @Override + Object writeReplace() { + return super.writeReplace(); + } + + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } } diff --git a/src/share/classes/java/time/chrono/ThaiBuddhistDate.java b/src/share/classes/java/time/chrono/ThaiBuddhistDate.java index 67799ad5af8197a70b1dda68b1df7465ff7f39c6..3d8f4078cc973dfbc2470cbc299f76b8a5e2b778 100644 --- a/src/share/classes/java/time/chrono/ThaiBuddhistDate.java +++ b/src/share/classes/java/time/chrono/ThaiBuddhistDate.java @@ -64,6 +64,7 @@ import static java.time.temporal.ChronoField.YEAR; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.io.InvalidObjectException; import java.io.Serializable; import java.time.Clock; import java.time.DateTimeException; @@ -106,7 +107,7 @@ public final class ThaiBuddhistDate /** * The underlying date. */ - private final LocalDate isoDate; + private final transient LocalDate isoDate; //----------------------------------------------------------------------- /** @@ -448,6 +449,28 @@ public final class ThaiBuddhistDate } //----------------------------------------------------------------------- + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws InvalidObjectException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } + + /** + * Writes the object using a + * dedicated serialized form. + * @serialData + *
+ * out.writeByte(10); // identifies a ThaiBuddhistDate + * out.writeInt(get(YEAR)); + * out.writeByte(get(MONTH_OF_YEAR)); + * out.writeByte(get(DAY_OF_MONTH)); + *+ * + * @return the instance of {@code Ser}, not null + */ private Object writeReplace() { return new Ser(Ser.THAIBUDDHIST_DATE_TYPE, this); } diff --git a/src/share/classes/java/time/chrono/ThaiBuddhistEra.java b/src/share/classes/java/time/chrono/ThaiBuddhistEra.java index d91eb81d79dcfe26aa6b5552f833d57efb4ef3a4..c549229d35ecd4d5ac1d2af1a1703590709e22b4 100644 --- a/src/share/classes/java/time/chrono/ThaiBuddhistEra.java +++ b/src/share/classes/java/time/chrono/ThaiBuddhistEra.java @@ -61,9 +61,6 @@ */ package java.time.chrono; -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; import java.time.DateTimeException; /** @@ -155,18 +152,4 @@ public enum ThaiBuddhistEra implements Era { return ordinal(); } - //----------------------------------------------------------------------- - private Object writeReplace() { - return new Ser(Ser.THAIBUDDHIST_ERA_TYPE, this); - } - - void writeExternal(DataOutput out) throws IOException { - out.writeByte(this.getValue()); - } - - static ThaiBuddhistEra readExternal(DataInput in) throws IOException { - byte eraValue = in.readByte(); - return ThaiBuddhistEra.of(eraValue); - } - } diff --git a/src/share/classes/java/time/zone/Ser.java b/src/share/classes/java/time/zone/Ser.java index e34126436af509a5ad38bf1a82ae23e2f551ce19..b2c3b259fb323f9d2ac7e703e33226e6fd484e03 100644 --- a/src/share/classes/java/time/zone/Ser.java +++ b/src/share/classes/java/time/zone/Ser.java @@ -119,9 +119,20 @@ final class Ser implements Externalizable { //----------------------------------------------------------------------- /** * Implements the {@code Externalizable} interface to write the object. + * @serialData + * Each serializable class is mapped to a type that is the first byte + * in the stream. Refer to each class {@code writeReplace} + * serialized form for the value of the type and sequence of values for the type. + * + *
{@code
*
+ * out.writeByte(2); // identifies a ZoneOffsetTransition
+ * out.writeEpochSec(toEpochSecond);
+ * out.writeOffset(offsetBefore);
+ * out.writeOfset(offsetAfter);
+ * }
+ *
* @return the replacing object, not null
*/
private Object writeReplace() {
diff --git a/src/share/classes/java/time/zone/ZoneOffsetTransitionRule.java b/src/share/classes/java/time/zone/ZoneOffsetTransitionRule.java
index ad52f82de558be3dc77121b8292839e0a8941556..20e97f023f83b7af137d2cf8956853ebea939ca8 100644
--- a/src/share/classes/java/time/zone/ZoneOffsetTransitionRule.java
+++ b/src/share/classes/java/time/zone/ZoneOffsetTransitionRule.java
@@ -67,6 +67,7 @@ import static java.time.temporal.TemporalAdjuster.previousOrSame;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.DayOfWeek;
import java.time.LocalDate;
@@ -231,7 +232,56 @@ public final class ZoneOffsetTransitionRule implements Serializable {
//-----------------------------------------------------------------------
/**
- * Uses a serialization delegate.
+ * Defend against malicious streams.
+ * @return never
+ * @throws InvalidObjectException always
+ */
+ private Object readResolve() throws InvalidObjectException {
+ throw new InvalidObjectException("Deserialization via serialization delegate");
+ }
+
+ /**
+ * Writes the object using a
+ * dedicated serialized form.
+ * @serialData
+ * Refer to the serialized form of
+ * ZoneRules.writeReplace
+ * for the encoding of epoch seconds and offsets.
+ * {@code
+ *
+ * out.writeByte(3); // identifies a ZoneOffsetTransition
+ * final int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
+ * final int stdOffset = standardOffset.getTotalSeconds();
+ * final int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
+ * final int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
+ * final int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
+ * final int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
+ * final int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
+ * final int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
+ * final int dowByte = (dow == null ? 0 : dow.getValue());
+ * int b = (month.getValue() << 28) + // 4 bits
+ * ((dom + 32) << 22) + // 6 bits
+ * (dowByte << 19) + // 3 bits
+ * (timeByte << 14) + // 5 bits
+ * (timeDefinition.ordinal() << 12) + // 2 bits
+ * (stdOffsetByte << 4) + // 8 bits
+ * (beforeByte << 2) + // 2 bits
+ * afterByte; // 2 bits
+ * out.writeInt(b);
+ * if (timeByte == 31) {
+ * out.writeInt(timeSecs);
+ * }
+ * if (stdOffsetByte == 255) {
+ * out.writeInt(stdOffset);
+ * }
+ * if (beforeByte == 3) {
+ * out.writeInt(offsetBefore.getTotalSeconds());
+ * }
+ * if (afterByte == 3) {
+ * out.writeInt(offsetAfter.getTotalSeconds());
+ * }
+ * }
+ *
*
* @return the replacing object, not null
*/
diff --git a/src/share/classes/java/time/zone/ZoneRules.java b/src/share/classes/java/time/zone/ZoneRules.java
index 070ad6e83981a3fea52d148043a6bb522c5be39d..064a2d8f817dbce952435fcb0ae511fc615331ea 100644
--- a/src/share/classes/java/time/zone/ZoneRules.java
+++ b/src/share/classes/java/time/zone/ZoneRules.java
@@ -64,6 +64,7 @@ package java.time.zone;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
@@ -145,7 +146,7 @@ public final class ZoneRules implements Serializable {
/**
* The map of recent transitions.
*/
- private final ConcurrentMap{@code
+ *
+ * out.writeByte(1); // identifies a ZoneRules
+ * out.writeInt(standardTransitions.length);
+ * for (long trans : standardTransitions) {
+ * Ser.writeEpochSec(trans, out);
+ * }
+ * for (ZoneOffset offset : standardOffsets) {
+ * Ser.writeOffset(offset, out);
+ * }
+ * out.writeInt(savingsInstantTransitions.length);
+ * for (long trans : savingsInstantTransitions) {
+ * Ser.writeEpochSec(trans, out);
+ * }
+ * for (ZoneOffset offset : wallOffsets) {
+ * Ser.writeOffset(offset, out);
+ * }
+ * out.writeByte(lastRules.length);
+ * for (ZoneOffsetTransitionRule rule : lastRules) {
+ * rule.writeExternal(out);
+ * }
+ * }
+ *
+ * + * Epoch second values used for offsets are encoded in a variable + * length form to make the common cases put fewer bytes in the stream. + *
{@code
+ *
+ * static void writeEpochSec(long epochSec, DataOutput out) throws IOException {
+ * if (epochSec >= -4575744000L && epochSec < 10413792000L && epochSec % 900 == 0) { // quarter hours between 1825 and 2300
+ * int store = (int) ((epochSec + 4575744000L) / 900);
+ * out.writeByte((store >>> 16) & 255);
+ * out.writeByte((store >>> 8) & 255);
+ * out.writeByte(store & 255);
+ * } else {
+ * out.writeByte(255);
+ * out.writeLong(epochSec);
+ * }
+ * }
+ * }
+ *
+ * + * ZoneOffset values are encoded in a variable length form so the + * common cases put fewer bytes in the stream. + *
{@code
*
+ * static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
+ * final int offsetSecs = offset.getTotalSeconds();
+ * int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127; // compress to -72 to +72
+ * out.writeByte(offsetByte);
+ * if (offsetByte == 127) {
+ * out.writeInt(offsetSecs);
+ * }
+ * }
+ *}
+ *
* @return the replacing object, not null
*/
private Object writeReplace() {
diff --git a/test/java/time/tck/java/time/chrono/TCKChronologySerialization.java b/test/java/time/tck/java/time/chrono/TCKChronologySerialization.java
index e9d5fb4f1da0efff530f733ae25c7802dc00cef6..35620ad755ed58a9a2e6803e6f5e36b451d6bbc6 100644
--- a/test/java/time/tck/java/time/chrono/TCKChronologySerialization.java
+++ b/test/java/time/tck/java/time/chrono/TCKChronologySerialization.java
@@ -97,7 +97,9 @@ public class TCKChronologySerialization {
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(chrono);
out.close();
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ byte[] bytes = baos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(bais);
@SuppressWarnings("unchecked")