Search in sources :

Example 56 with InvalidObjectException

use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.

the class BatchUpdateException method readObject.

/**
     * readObject is called to restore the state of the
     * {@code BatchUpdateException} from a stream.
     */
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = s.readFields();
    int[] tmp = (int[]) fields.get("updateCounts", null);
    long[] tmp2 = (long[]) fields.get("longUpdateCounts", null);
    if (tmp != null && tmp2 != null && tmp.length != tmp2.length)
        throw new InvalidObjectException("update counts are not the expected size");
    if (tmp != null)
        updateCounts = tmp.clone();
    if (tmp2 != null)
        longUpdateCounts = tmp2.clone();
    if (updateCounts == null && longUpdateCounts != null)
        updateCounts = copyUpdateCount(longUpdateCounts);
    if (longUpdateCounts == null && updateCounts != null)
        longUpdateCounts = copyUpdateCount(updateCounts);
}
Also used : InvalidObjectException(java.io.InvalidObjectException) ObjectInputStream(java.io.ObjectInputStream)

Example 57 with InvalidObjectException

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

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 58 with InvalidObjectException

use of java.io.InvalidObjectException in project checker-framework by typetools.

the class UrlDeserializedState method fabricateNewURL.

private URL fabricateNewURL() throws InvalidObjectException {
    // create URL string from deserialized object
    URL replacementURL = null;
    String urlString = tempState.reconstituteUrlString();
    try {
        replacementURL = new URL(urlString);
    } catch (MalformedURLException mEx) {
        resetState();
        InvalidObjectException invoEx = new InvalidObjectException("Malformed URL: " + urlString);
        invoEx.initCause(mEx);
        throw invoEx;
    }
    replacementURL.setSerializedHashCode(tempState.getHashCode());
    resetState();
    return replacementURL;
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Example 59 with InvalidObjectException

use of java.io.InvalidObjectException in project Lucee by lucee.

the class HashMapPro 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();
    if (loadFactor <= 0 || Float.isNaN(loadFactor))
        throw new InvalidObjectException("Illegal load factor: " + loadFactor);
    // set hashSeed (can only happen after VM boot)
    Holder.UNSAFE.putIntVolatile(this, Holder.HASHSEED_OFFSET, Hashing.randomHashSeed(this));
    // Read in number of buckets and allocate the bucket array;
    // ignored
    s.readInt();
    // Read number of mappings
    int mappings = s.readInt();
    if (mappings < 0)
        throw new InvalidObjectException("Illegal mappings count: " + mappings);
    int initialCapacity = (int) Math.min(// and desired load (if >= 0.25)
    mappings * Math.min(1 / loadFactor, 4.0f), // we have limits...
    HashMapPro.MAXIMUM_CAPACITY);
    int capacity = 1;
    // find smallest power of two which holds all mappings
    while (capacity < initialCapacity) {
        capacity <<= 1;
    }
    table = new Entry[capacity];
    threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1);
    // useAltHashing = sun.misc.VM.isBooted() && (capacity >= Holder.ALTERNATIVE_HASHING_THRESHOLD);
    // Give subclass a chance to do its thing.
    init();
    // Read the keys and values, and put the mappings in the HashMap
    for (int i = 0; i < mappings; i++) {
        K key = (K) s.readObject();
        V value = (V) s.readObject();
        putForCreate(key, value);
    }
}
Also used : InvalidObjectException(java.io.InvalidObjectException) lucee.aprint(lucee.aprint)

Example 60 with InvalidObjectException

use of java.io.InvalidObjectException in project rocketmq-externals by apache.

the class RedisURI method readObject.

private void readObject(ObjectInputStream is) throws ClassNotFoundException, IOException {
    this.port = -1;
    is.defaultReadObject();
    try {
        parse(this.string);
    } catch (URISyntaxException x) {
        IOException y = new InvalidObjectException("Invalid Redis URI");
        y.initCause(x);
        throw y;
    }
}
Also used : InvalidObjectException(java.io.InvalidObjectException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

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