jdk/src/share/classes/java/time/temporal/WeekFields.java
changeset 22081 86eb26ff8f2b
parent 21331 8ee181e7e48b
child 22566 4ebe53dd7814
--- a/jdk/src/share/classes/java/time/temporal/WeekFields.java	Fri Dec 20 08:59:52 2013 -0800
+++ b/jdk/src/share/classes/java/time/temporal/WeekFields.java	Fri Dec 20 13:06:23 2013 -0500
@@ -72,7 +72,9 @@
 import static java.time.temporal.ChronoUnit.WEEKS;
 import static java.time.temporal.ChronoUnit.YEARS;
 
+import java.io.IOException;
 import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.time.DateTimeException;
 import java.time.DayOfWeek;
@@ -340,6 +342,25 @@
 
     //-----------------------------------------------------------------------
     /**
+     * Restore the state of a WeekFields from the stream.
+     * Check that the values are valid.
+     * @throws InvalidObjectException if the serialized object has an invalid
+     *     value for firstDayOfWeek or minimalDays.
+     */
+    private void readObject(ObjectInputStream s)
+         throws IOException, ClassNotFoundException, InvalidObjectException
+    {
+        s.defaultReadObject();
+        if (firstDayOfWeek == null) {
+            throw new InvalidObjectException("firstDayOfWeek is null");
+        }
+
+        if (minimalDays < 1 || minimalDays > 7) {
+            throw new InvalidObjectException("Minimal number of days is invalid");
+        }
+    }
+
+    /**
      * Return the singleton WeekFields associated with the
      * {@code firstDayOfWeek} and {@code minimalDays}.
      * @return the singleton WeekFields for the firstDayOfWeek and minimalDays.