Search in sources :

Example 81 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 82 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("Deserializing persistence-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 83 with InvalidObjectException

use of java.io.InvalidObjectException in project fqrouter by fqrouter.

the class DNSName method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    byte[] bytes;
    if ((bytes = this.bytes) == null)
        throw new InvalidObjectException("bytes: null");
    if (bytes.length <= 0 || lengthOf(bytes, 0) != bytes.length)
        throw new InvalidObjectException("Bad resource name");
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Example 84 with InvalidObjectException

use of java.io.InvalidObjectException in project fqrouter by fqrouter.

the class DNSRecord method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    DNSName rName;
    byte[] rDataBytes;
    if ((rName = this.rName) == null)
        throw new InvalidObjectException("rName: null");
    if ((rDataBytes = this.rDataBytes) == null)
        throw new InvalidObjectException("rDataBytes: null");
    if ((rDataBytes.length & ~RDATA_LEN_MASK) != 0)
        throw new InvalidObjectException("rDataBytes length: " + UnsignedInt.toString(rDataBytes.length, false));
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Example 85 with InvalidObjectException

use of java.io.InvalidObjectException in project Stringlate by LonamiWebs.

the class TranslateActivity method getCreateExportRoot.

private File getCreateExportRoot() {
    String path;
    try {
        path = getString(R.string.app_name) + "/" + mRepo.toOwnerRepo();
    } catch (InvalidObjectException ignored) {
        path = getString(R.string.app_name);
    }
    File root = new File(Environment.getExternalStorageDirectory(), path);
    if (root.isDirectory())
        root.mkdirs();
    return root;
}
Also used : InvalidObjectException(java.io.InvalidObjectException) LocaleString(io.github.lonamiwebs.stringlate.classes.locales.LocaleString) DocumentFile(android.support.v4.provider.DocumentFile) File(java.io.File)

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