use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class HashMap method readObject.
/**
* Reconstitute the {@code HashMap} instance from a stream (i.e.,
* deserialize it).
*/
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
// Read in the threshold (ignored), loadfactor, and any hidden stuff
s.defaultReadObject();
reinitialize();
if (loadFactor <= 0 || Float.isNaN(loadFactor))
throw new InvalidObjectException("Illegal load factor: " + loadFactor);
// Read and ignore number of buckets
s.readInt();
// Read number of mappings (size)
int mappings = s.readInt();
if (mappings < 0)
throw new InvalidObjectException("Illegal mappings count: " + mappings);
else if (mappings > 0) {
// (if zero, use defaults)
// Size the table using given load factor only if within
// range of 0.25...4.0
float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);
float fc = (float) mappings / lf + 1.0f;
int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ? DEFAULT_INITIAL_CAPACITY : (fc >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : tableSizeFor((int) fc));
float ft = (float) cap * lf;
threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? (int) ft : Integer.MAX_VALUE);
@SuppressWarnings({ "rawtypes", "unchecked" }) Node<K, V>[] tab = (Node<K, V>[]) new Node[cap];
table = tab;
// Read the keys and values, and put the mappings in the HashMap
for (int i = 0; i < mappings; i++) {
@SuppressWarnings("unchecked") K key = (K) s.readObject();
@SuppressWarnings("unchecked") V value = (V) s.readObject();
putVal(hash(key), key, value, false, false);
}
}
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class JMXServiceURL method readObject.
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
ObjectInputStream.GetField gf = inputStream.readFields();
String h = (String) gf.get("host", null);
int p = (int) gf.get("port", -1);
String proto = (String) gf.get("protocol", null);
String url = (String) gf.get("urlPath", null);
if (proto == null || url == null || h == null) {
StringBuilder sb = new StringBuilder(INVALID_INSTANCE_MSG).append('[');
boolean empty = true;
if (proto == null) {
sb.append("protocol=null");
empty = false;
}
if (h == null) {
sb.append(empty ? "" : ",").append("host=null");
empty = false;
}
if (url == null) {
sb.append(empty ? "" : ",").append("urlPath=null");
}
sb.append(']');
throw new InvalidObjectException(sb.toString());
}
if (h.contains("[") || h.contains("]")) {
throw new InvalidObjectException("Invalid host name: " + h);
}
try {
validate(proto, h, p, url);
this.protocol = proto;
this.host = h;
this.port = p;
this.urlPath = url;
} catch (MalformedURLException e) {
throw new InvalidObjectException(INVALID_INSTANCE_MSG + ": " + e.getMessage());
}
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class TCKValueRangeSerialization method test_invalid_serialform.
@Test
public void test_invalid_serialform() throws Exception {
byte[] template = { (byte) 172, (byte) 237, 0, 5, 115, 114, 0, 29, 106, 97, /* ¬ í s r j a */
118, 97, 46, 116, 105, 109, 101, 46, 116, 101, /* v a . t i m e . t e */
109, 112, 111, 114, 97, 108, 46, 86, 97, 108, /* m p o r a l . V a l */
117, 101, 82, 97, 110, 103, 101, (byte) 154, 113, (byte) 169, /* u e R a n g e q © */
86, (byte) 242, (byte) 205, 90, (byte) 184, 2, 0, 4, 74, 0, /* V ò Í Z ¸ J */
10, 109, 97, 120, 76, 97, 114, 103, 101, 115, /* m a x L a r g e s */
116, 74, 0, 11, 109, 97, 120, 83, 109, 97, /* t J m a x S m a */
108, 108, 101, 115, 116, 74, 0, 10, 109, 105, /* l l e s t J m i */
110, 76, 97, 114, 103, 101, 115, 116, 74, 0, /* n L a r g e s t J */
11, 109, 105, 110, 83, 109, 97, 108, 108, 101, /* m i n S m a l l e */
115, 116, 120, 112, 0, 0, 0, 0, 0, 0, /* s t x p */
0, 40, 0, 0, 0, 0, 0, 0, 0, 30, /* ( */
0, 0, 0, 0, 0, 0, 0, 20, 0, 0, /* */
0, 0, 0, 0, 0, 10 };
// minSmallest > minLargest, insert invalid values and deserialize
byte[] bad1 = { 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 4 };
byte[] val = Arrays.copyOf(template, template.length);
System.arraycopy(bad1, 0, val, 114, bad1.length);
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(val))) {
in.readObject();
fail("Invalid minSmallest > minLargest " + ValueRange.class.getName());
} catch (InvalidObjectException ioe) {
// Expected exception
}
// maxSmallest > maxLargest, insert invalid values and deserialize
byte[] bad2 = { 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 3 };
val = Arrays.copyOf(template, template.length);
System.arraycopy(bad1, 0, val, 114, bad2.length);
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(val))) {
in.readObject();
fail("Invalid maxSmallest > maxLargest " + ValueRange.class.getName());
} catch (InvalidObjectException ioe) {
// Expected exception
}
// minLagest > maxLargest, insert invalid values and deserialize
byte[] bad3 = { 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 3, 0, 0, 0, 4 };
val = Arrays.copyOf(template, template.length);
System.arraycopy(bad1, 0, val, 114, bad3.length);
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(val))) {
in.readObject();
fail("Invalid minLagest > maxLargest " + ValueRange.class.getName());
} catch (InvalidObjectException ioe) {
// Expected exception
}
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class OpenType method readObject.
/**
* Deserializes an {@link OpenType} from an {@link java.io.ObjectInputStream}.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
checkClassNameOverride();
ObjectInputStream.GetField fields = in.readFields();
final String classNameField;
final String descriptionField;
final String typeNameField;
try {
classNameField = validClassName((String) fields.get("className", null));
descriptionField = valid("description", (String) fields.get("description", null));
typeNameField = valid("typeName", (String) fields.get("typeName", null));
} catch (Exception e) {
IOException e2 = new InvalidObjectException(e.getMessage());
e2.initCause(e);
throw e2;
}
className = classNameField;
description = descriptionField;
typeName = typeNameField;
isArray = (className.startsWith("["));
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class RelationNotification method readObject.
/**
* Deserializes a {@link RelationNotification} from an {@link ObjectInputStream}.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
String tmpRelationId, tmpRelationTypeName, tmpRoleName;
ObjectName tmpRelationObjName;
List<ObjectName> tmpNewRoleValue, tmpOldRoleValue, tmpUnregMBeanList;
ObjectInputStream.GetField fields = in.readFields();
if (compat) {
tmpRelationId = (String) fields.get("myRelId", null);
tmpRelationTypeName = (String) fields.get("myRelTypeName", null);
tmpRoleName = (String) fields.get("myRoleName", null);
tmpRelationObjName = (ObjectName) fields.get("myRelObjName", null);
tmpNewRoleValue = cast(fields.get("myNewRoleValue", null));
tmpOldRoleValue = cast(fields.get("myOldRoleValue", null));
tmpUnregMBeanList = cast(fields.get("myUnregMBeanList", null));
} else {
tmpRelationId = (String) fields.get("relationId", null);
tmpRelationTypeName = (String) fields.get("relationTypeName", null);
tmpRoleName = (String) fields.get("roleName", null);
tmpRelationObjName = (ObjectName) fields.get("relationObjName", null);
tmpNewRoleValue = cast(fields.get("newRoleValue", null));
tmpOldRoleValue = cast(fields.get("oldRoleValue", null));
tmpUnregMBeanList = cast(fields.get("unregisterMBeanList", null));
}
// Validate fields we just read, throw InvalidObjectException
// if something goes wrong
String notifType = super.getType();
if (!isValidBasic(notifType, super.getSource(), tmpRelationId, tmpRelationTypeName) || (!isValidCreate(notifType) && !isValidUpdate(notifType, tmpRoleName, tmpNewRoleValue, tmpOldRoleValue))) {
super.setSource(null);
throw new InvalidObjectException("Invalid object read");
}
// assign deserialized vaules to object fields
relationObjName = safeGetObjectName(tmpRelationObjName);
newRoleValue = safeGetObjectNameList(tmpNewRoleValue);
oldRoleValue = safeGetObjectNameList(tmpOldRoleValue);
unregisterMBeanList = safeGetObjectNameList(tmpUnregMBeanList);
relationId = tmpRelationId;
relationTypeName = tmpRelationTypeName;
roleName = tmpRoleName;
}
Aggregations