8189977: Improve permission portability

Reviewed-by: rriggs
This commit is contained in:
Weijun Wang 2017-12-06 21:17:19 +08:00
parent a7c9c021ba
commit 0b873290a4
2 changed files with 30 additions and 0 deletions

View file

@ -25,6 +25,9 @@
package java.util;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.StreamCorruptedException;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
@ -1168,6 +1171,29 @@ public class Vector<E>
es[i] = null;
}
/**
* Loads a {@code Vector} instance from a stream
* (that is, deserializes it).
* This method performs checks to ensure the consistency
* of the fields.
*
* @param in the stream
* @throws java.io.IOException if an I/O error occurs
* @throws ClassNotFoundException if the stream contains data
* of a non-existing class
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
ObjectInputStream.GetField gfields = in.readFields();
int count = gfields.get("elementCount", 0);
Object[] data = (Object[])gfields.get("elementData", null);
if (count < 0 || data == null || count > data.length) {
throw new StreamCorruptedException("Inconsistent vector internals");
}
elementCount = count;
elementData = data.clone();
}
/**
* Saves the state of the {@code Vector} instance to a stream
* (that is, serializes it).