use of java.io.InvalidObjectException in project voltdb by VoltDB.
the class ImmutableListMultimap method readObject.
// java.io.ObjectInputStream
@GwtIncompatible
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
int keyCount = stream.readInt();
if (keyCount < 0) {
throw new InvalidObjectException("Invalid key count " + keyCount);
}
ImmutableMap.Builder<Object, ImmutableList<Object>> builder = ImmutableMap.builder();
int tmpSize = 0;
for (int i = 0; i < keyCount; i++) {
Object key = stream.readObject();
int valueCount = stream.readInt();
if (valueCount <= 0) {
throw new InvalidObjectException("Invalid value count " + valueCount);
}
ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();
for (int j = 0; j < valueCount; j++) {
valuesBuilder.add(stream.readObject());
}
builder.put(key, valuesBuilder.build());
tmpSize += valueCount;
}
ImmutableMap<Object, ImmutableList<Object>> tmpMap;
try {
tmpMap = builder.build();
} catch (IllegalArgumentException e) {
throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
}
FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
}
use of java.io.InvalidObjectException in project voltdb by VoltDB.
the class ImmutableSetMultimap method readObject.
// java.io.ObjectInputStream
@GwtIncompatible
// Serialization type safety is at the caller's mercy.
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
Comparator<Object> valueComparator = (Comparator<Object>) stream.readObject();
int keyCount = stream.readInt();
if (keyCount < 0) {
throw new InvalidObjectException("Invalid key count " + keyCount);
}
ImmutableMap.Builder<Object, ImmutableSet<Object>> builder = ImmutableMap.builder();
int tmpSize = 0;
for (int i = 0; i < keyCount; i++) {
Object key = stream.readObject();
int valueCount = stream.readInt();
if (valueCount <= 0) {
throw new InvalidObjectException("Invalid value count " + valueCount);
}
ImmutableSet.Builder<Object> valuesBuilder = valuesBuilder(valueComparator);
for (int j = 0; j < valueCount; j++) {
valuesBuilder.add(stream.readObject());
}
ImmutableSet<Object> valueSet = valuesBuilder.build();
if (valueSet.size() != valueCount) {
throw new InvalidObjectException("Duplicate key-value pairs exist for key " + key);
}
builder.put(key, valueSet);
tmpSize += valueCount;
}
ImmutableMap<Object, ImmutableSet<Object>> tmpMap;
try {
tmpMap = builder.build();
} catch (IllegalArgumentException e) {
throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
}
FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
FieldSettersHolder.EMPTY_SET_FIELD_SETTER.set(this, emptySet(valueComparator));
}
use of java.io.InvalidObjectException in project geode by apache.
the class OpenMethod method invokeWithOpenReturn.
Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
final Object[] javaParams;
try {
javaParams = fromOpenParameters(params);
} catch (InvalidObjectException e) {
final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
throw new MBeanException(e, msg);
}
final Object javaReturn = method.invoke(obj, javaParams);
try {
return returnTypeConverter.toOpenValue(javaReturn);
} catch (OpenDataException e) {
final String msg = methodName() + ": cannot convert return " + "value to open value: " + e;
throw new MBeanException(e, msg);
}
}
use of java.io.InvalidObjectException in project geode by apache.
the class TableConverter method fromNonNullOpenValue.
public Object fromNonNullOpenValue(Object openValue) throws InvalidObjectException {
final TabularData table = (TabularData) openValue;
final Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
final Map<Object, Object> valueMap = sortedMap ? OpenTypeUtil.newSortedMap() : OpenTypeUtil.newMap();
for (CompositeData row : rows) {
final Object key = keyConverter.fromOpenValue(row.get("key"));
final Object value = valueConverter.fromOpenValue(row.get("value"));
if (valueMap.put(key, value) != null) {
final String msg = "Duplicate entry in TabularData: key=" + key;
throw new InvalidObjectException(msg);
}
}
return valueMap;
}
use of java.io.InvalidObjectException in project platform_frameworks_base by android.
the class RationalTest method testSerialize.
@SmallTest
public void testSerialize() throws ClassNotFoundException, IOException {
/*
* Check correct [de]serialization
*/
assertEqualsAfterSerializing(ZERO);
assertEqualsAfterSerializing(NaN);
assertEqualsAfterSerializing(NEGATIVE_INFINITY);
assertEqualsAfterSerializing(POSITIVE_INFINITY);
assertEqualsAfterSerializing(UNIT);
assertEqualsAfterSerializing(new Rational(100, 200));
assertEqualsAfterSerializing(new Rational(-100, 200));
assertEqualsAfterSerializing(new Rational(5, 1));
assertEqualsAfterSerializing(new Rational(Integer.MAX_VALUE, Integer.MIN_VALUE));
/*
* Check bad deserialization fails
*/
try {
// [0, 100] , should be [0, 1]
Rational badZero = createIllegalRational(0, 100);
Rational results = serializeRoundTrip(badZero);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [100, 0] , should be [1, 0]
Rational badPosInfinity = createIllegalRational(100, 0);
Rational results = serializeRoundTrip(badPosInfinity);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
Rational badNegInfinity = // [-100, 0] , should be [-1, 0]
createIllegalRational(-100, 0);
Rational results = serializeRoundTrip(badNegInfinity);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [2,4] , should be [1, 2]
Rational badReduced = createIllegalRational(2, 4);
Rational results = serializeRoundTrip(badReduced);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [-2, 4] should be [-1, 2]
Rational badReducedNeg = createIllegalRational(-2, 4);
Rational results = serializeRoundTrip(badReducedNeg);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
}
Aggregations