Search in sources :

Example 1 with InvalidObjectException

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);
}
Also used : InvalidObjectException(java.io.InvalidObjectException) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Example 2 with InvalidObjectException

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));
}
Also used : InvalidObjectException(java.io.InvalidObjectException) Comparator(java.util.Comparator) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Example 3 with InvalidObjectException

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);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) MBeanException(javax.management.MBeanException) InvalidObjectException(java.io.InvalidObjectException)

Example 4 with InvalidObjectException

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;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) InvalidObjectException(java.io.InvalidObjectException) TabularData(javax.management.openmbean.TabularData)

Example 5 with InvalidObjectException

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
    }
}
Also used : Rational(android.util.Rational) InvalidObjectException(java.io.InvalidObjectException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

InvalidObjectException (java.io.InvalidObjectException)88 ObjectInputStream (java.io.ObjectInputStream)18 IOException (java.io.IOException)15 ByteArrayInputStream (java.io.ByteArrayInputStream)7 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Rational (android.util.Rational)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 GwtIncompatible (com.google.common.annotations.GwtIncompatible)4 ObjectOutputStream (java.io.ObjectOutputStream)4 SimpleTimeZone (java.util.SimpleTimeZone)3 TimeZone (java.util.TimeZone)3 GwtIncompatible (com.google_voltpatches.common.annotations.GwtIncompatible)2 Point (java.awt.Point)2 File (java.io.File)2 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 RemoteRef (java.rmi.server.RemoteRef)2 Comparator (java.util.Comparator)2 CompositeData (javax.management.openmbean.CompositeData)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 JSONObject (org.json.JSONObject)2