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;
}
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);
}
}
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;
}
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);
}
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));
}
Aggregations