Search in sources :

Example 31 with InvalidObjectException

use of java.io.InvalidObjectException in project hudson-2.x by hudson.

the class SimpleScheduledRetentionStrategy method readResolve.

protected synchronized Object readResolve() throws ObjectStreamException {
    try {
        tabs = CronTabList.create(startTimeSpec);
        lastChecked = new GregorianCalendar();
        this.lastChecked.add(Calendar.MINUTE, -1);
        nextStop = Long.MIN_VALUE;
        nextStart = Long.MIN_VALUE;
        lastStop = Long.MAX_VALUE;
        lastStart = Long.MAX_VALUE;
    } catch (ANTLRException e) {
        InvalidObjectException x = new InvalidObjectException(e.getMessage());
        x.initCause(e);
        throw x;
    }
    return this;
}
Also used : ANTLRException(antlr.ANTLRException) GregorianCalendar(java.util.GregorianCalendar) InvalidObjectException(java.io.InvalidObjectException)

Example 32 with InvalidObjectException

use of java.io.InvalidObjectException in project bazel by bazelbuild.

the class CompactHashSet method readObject.

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    int length = stream.readInt();
    float loadFactor = stream.readFloat();
    int elementCount = stream.readInt();
    try {
        init(length, loadFactor);
    } catch (IllegalArgumentException e) {
        throw new InvalidObjectException(e.getMessage());
    }
    for (int i = elementCount; --i >= 0; ) {
        E element = (E) stream.readObject();
        add(element);
    }
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Example 33 with InvalidObjectException

use of java.io.InvalidObjectException in project hibernate-orm by hibernate.

the class StatefulPersistenceContext method deserialize.

/**
	 * Used by the owning session to explicitly control deserialization of the persistence context.
	 *
	 * @param ois The stream from which the persistence context should be read
	 * @param session The owning session
	 *
	 * @return The deserialized StatefulPersistenceContext
	 *
	 * @throws IOException deserialization errors.
	 * @throws ClassNotFoundException deserialization errors.
	 */
public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException {
    final boolean tracing = LOG.isTraceEnabled();
    if (tracing) {
        LOG.trace("Serializing persistent-context");
    }
    final StatefulPersistenceContext rtn = new StatefulPersistenceContext(session);
    SessionFactoryImplementor sfi = session.getFactory();
    try {
        rtn.defaultReadOnly = ois.readBoolean();
        // todo : we can actually just determine this from the incoming EntityEntry-s
        rtn.hasNonReadOnlyEntities = ois.readBoolean();
        int count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] entitiesByKey entries");
        }
        rtn.entitiesByKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitiesByKey.put(EntityKey.deserialize(ois, sfi), ois.readObject());
        }
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] entitiesByUniqueKey entries");
        }
        rtn.entitiesByUniqueKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitiesByUniqueKey.put(EntityUniqueKey.deserialize(ois, session), ois.readObject());
        }
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] proxiesByKey entries");
        }
        //noinspection unchecked
        rtn.proxiesByKey = new ConcurrentReferenceHashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count, .75f, 1, ConcurrentReferenceHashMap.ReferenceType.STRONG, ConcurrentReferenceHashMap.ReferenceType.WEAK, null);
        for (int i = 0; i < count; i++) {
            final EntityKey ek = EntityKey.deserialize(ois, sfi);
            final Object proxy = ois.readObject();
            if (proxy instanceof HibernateProxy) {
                ((HibernateProxy) proxy).getHibernateLazyInitializer().setSession(session);
                rtn.proxiesByKey.put(ek, proxy);
            } else {
                // otherwise, the proxy was pruned during the serialization process
                if (tracing) {
                    LOG.trace("Encountered pruned proxy");
                }
            }
        }
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] entitySnapshotsByKey entries");
        }
        rtn.entitySnapshotsByKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitySnapshotsByKey.put(EntityKey.deserialize(ois, sfi), ois.readObject());
        }
        rtn.entityEntryContext = EntityEntryContext.deserialize(ois, rtn);
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] collectionsByKey entries");
        }
        rtn.collectionsByKey = new HashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.collectionsByKey.put(CollectionKey.deserialize(ois, session), (PersistentCollection) ois.readObject());
        }
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] collectionEntries entries");
        }
        rtn.collectionEntries = IdentityMap.instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            final PersistentCollection pc = (PersistentCollection) ois.readObject();
            final CollectionEntry ce = CollectionEntry.deserialize(ois, session);
            pc.setCurrentSession(session);
            rtn.collectionEntries.put(pc, ce);
        }
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries");
        }
        rtn.arrayHolders = new IdentityHashMap<>(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.arrayHolders.put(ois.readObject(), (PersistentCollection) ois.readObject());
        }
        count = ois.readInt();
        if (tracing) {
            LOG.trace("Starting deserialization of [" + count + "] nullifiableEntityKey entries");
        }
        rtn.nullifiableEntityKeys = new HashSet<>();
        for (int i = 0; i < count; i++) {
            rtn.nullifiableEntityKeys.add(EntityKey.deserialize(ois, sfi));
        }
    } catch (HibernateException he) {
        throw new InvalidObjectException(he.getMessage());
    }
    return rtn;
}
Also used : CollectionEntry(org.hibernate.engine.spi.CollectionEntry) HibernateException(org.hibernate.HibernateException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) HibernateProxy(org.hibernate.proxy.HibernateProxy) EntityKey(org.hibernate.engine.spi.EntityKey) PersistentCollection(org.hibernate.collection.spi.PersistentCollection) InvalidObjectException(java.io.InvalidObjectException)

Example 34 with InvalidObjectException

use of java.io.InvalidObjectException in project guava by hceylan.

the class ImmutableSetMultimap method readObject.

@GwtIncompatible("java.io.ObjectInputStream")
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.copyOf(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) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 35 with InvalidObjectException

use of java.io.InvalidObjectException in project guava by google.

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.common.annotations.GwtIncompatible)

Aggregations

InvalidObjectException (java.io.InvalidObjectException)56 ObjectInputStream (java.io.ObjectInputStream)13 IOException (java.io.IOException)8 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