Search in sources :

Example 6 with InvalidObjectException

use of java.io.InvalidObjectException in project XobotOS by xamarin.

the class ImmutableSetMultimap method readObject.

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, 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);
        }
        Object[] array = new Object[valueCount];
        for (int j = 0; j < valueCount; j++) {
            array[j] = stream.readObject();
        }
        ImmutableSet<Object> valueSet = ImmutableSet.of(array);
        if (valueSet.size() != array.length) {
            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);
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Example 7 with InvalidObjectException

use of java.io.InvalidObjectException in project android_frameworks_base by DirtyUnicorns.

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)

Example 8 with InvalidObjectException

use of java.io.InvalidObjectException in project android_frameworks_base by AOSPA.

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)

Example 9 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 10 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)

Aggregations

InvalidObjectException (java.io.InvalidObjectException)54 ObjectInputStream (java.io.ObjectInputStream)13 IOException (java.io.IOException)7 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Rational (android.util.Rational)5 GwtIncompatible (com.google.common.annotations.GwtIncompatible)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 GwtIncompatible (com.google_voltpatches.common.annotations.GwtIncompatible)2 Point (java.awt.Point)2 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 RemoteRef (java.rmi.server.RemoteRef)2 Comparator (java.util.Comparator)2 SimpleTimeZone (java.util.SimpleTimeZone)2 TimeZone (java.util.TimeZone)2 MBeanException (javax.management.MBeanException)2 OpenDataException (javax.management.openmbean.OpenDataException)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 ANTLRException (antlr.ANTLRException)1