changeset 17444:44e9ee7b72ef

8189284: More refactoring for deserialization cases Reviewed-by: rriggs, igerasim, rhalade, skoivu
author igerasim
date Tue, 28 Nov 2017 14:09:11 -0800
parents bf0c7adcb6f9
children 905c01632fa3
files src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Wed Nov 29 13:11:21 2017 -0800
+++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Tue Nov 28 14:09:11 2017 -0800
@@ -1608,4 +1608,30 @@
         }
     }
 
+    /**
+     * Deserializes this queue and then checks some invariants.
+     *
+     * @param s the input stream
+     * @throws ClassNotFoundException if the class of a serialized object
+     *         could not be found
+     * @throws java.io.InvalidObjectException if invariants are violated
+     * @throws java.io.IOException if an I/O error occurs
+     */
+    private void readObject(java.io.ObjectInputStream s)
+        throws java.io.IOException, ClassNotFoundException {
+
+        // Read in items array and various fields
+        s.defaultReadObject();
+
+        // Check invariants over count and index fields. Note that
+        // if putIndex==takeIndex, count can be either 0 or items.length.
+        if (items.length == 0 ||
+            takeIndex < 0 || takeIndex >= items.length ||
+            putIndex  < 0 || putIndex  >= items.length ||
+            count < 0     || count     >  items.length ||
+            Math.floorMod(putIndex - takeIndex, items.length) !=
+            Math.floorMod(count, items.length)) {
+            throw new java.io.InvalidObjectException("invariants violated");
+        }
+    }
 }