use of java.io.ObjectStreamClass in project tetrad by cmu-phil.
the class DecompressibleInputStream method readClassDescriptor.
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
// initially streams descriptor
ObjectStreamClass resultClassDescriptor = super.readClassDescriptor();
// the class in the local JVM that this descriptor represents.
Class localClass;
try {
localClass = Class.forName(resultClassDescriptor.getName());
} catch (ClassNotFoundException e) {
LOGGER.error("No local class for " + resultClassDescriptor.getName(), e);
return resultClassDescriptor;
}
ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
if (localClassDescriptor != null) {
// only if class implements serializable
final long localSUID = localClassDescriptor.getSerialVersionUID();
final long streamSUID = resultClassDescriptor.getSerialVersionUID();
if (streamSUID != localSUID) {
// check for serialVersionUID mismatch.
// Use local class descriptor for deserialization
resultClassDescriptor = localClassDescriptor;
}
}
return resultClassDescriptor;
}
use of java.io.ObjectStreamClass in project evosuite by EvoSuite.
the class CreateClassResetClassAdapter method determineSerialisableUID.
@Deprecated
private void determineSerialisableUID() {
try {
Class<?> clazz = Class.forName(className.replace('/', '.'), false, MethodCallReplacementClassAdapter.class.getClassLoader());
if (Serializable.class.isAssignableFrom(clazz)) {
ObjectStreamClass c = ObjectStreamClass.lookup(clazz);
serialUID = c.getSerialVersionUID();
}
} catch (ClassNotFoundException e) {
logger.info("Failed to add serialId to class " + className + ": " + e.getMessage());
}
}
use of java.io.ObjectStreamClass in project HotswapAgent by HotswapProjects.
the class ProxyObjectInputStream method readClassDescriptor.
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
boolean isProxy = readBoolean();
if (isProxy) {
String name = (String) readObject();
Class superClass = loader.loadClass(name);
int length = readInt();
Class[] interfaces = new Class[length];
for (int i = 0; i < length; i++) {
name = (String) readObject();
interfaces[i] = loader.loadClass(name);
}
length = readInt();
byte[] signature = new byte[length];
read(signature);
ProxyFactory factory = new ProxyFactory();
// we must always use the cache and never use writeReplace when using
// ProxyObjectOutputStream and ProxyObjectInputStream
factory.setUseCache(true);
factory.setUseWriteReplace(false);
factory.setSuperclass(superClass);
factory.setInterfaces(interfaces);
Class proxyClass = factory.createClass(signature);
return ObjectStreamClass.lookup(proxyClass);
} else {
return super.readClassDescriptor();
}
}
use of java.io.ObjectStreamClass in project apex-core by apache.
the class FSRecoveryHandler method restore.
@Override
public Object restore() throws IOException {
FileContext fc = FileContext.getFileContext(fs.getUri());
// recover from wherever it was left
if (fc.util().exists(snapshotBackupPath)) {
LOG.warn("Incomplete checkpoint, reverting to {}", snapshotBackupPath);
fc.rename(snapshotBackupPath, snapshotPath, Rename.OVERWRITE);
// combine logs (w/o append, create new file)
Path tmpLogPath = new Path(basedir, "log.combined");
try (FSDataOutputStream fsOut = fc.create(tmpLogPath, EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE))) {
try (FSDataInputStream fsIn = fc.open(logBackupPath)) {
IOUtils.copy(fsIn, fsOut);
}
try (FSDataInputStream fsIn = fc.open(logPath)) {
IOUtils.copy(fsIn, fsOut);
}
}
fc.rename(tmpLogPath, logPath, Rename.OVERWRITE);
fc.delete(logBackupPath, false);
} else {
// failure between log rotation and writing checkpoint
if (fc.util().exists(logBackupPath)) {
LOG.warn("Found {}, did checkpointing fail?", logBackupPath);
fc.rename(logBackupPath, logPath, Rename.OVERWRITE);
}
}
if (!fc.util().exists(snapshotPath)) {
LOG.debug("No existing checkpoint.");
return null;
}
LOG.debug("Reading checkpoint {}", snapshotPath);
InputStream is = fc.open(snapshotPath);
// indeterministic class loading behavior
// http://stackoverflow.com/questions/9110677/readresolve-not-working-an-instance-of-guavas-serializedform-appears
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try (ObjectInputStream ois = new ObjectInputStream(is) {
@Override
protected Class<?> resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException {
return Class.forName(objectStreamClass.getName(), true, loader);
}
}) {
return ois.readObject();
} catch (ClassNotFoundException cnfe) {
throw new IOException("Failed to read checkpointed state", cnfe);
}
}
use of java.io.ObjectStreamClass in project graal by oracle.
the class SerializationBuilder method registerIncludingAssociatedClasses.
private void registerIncludingAssociatedClasses(ConfigurationCondition condition, Class<?> clazz, Set<Class<?>> alreadyVisited) {
if (alreadyVisited.contains(clazz)) {
return;
}
alreadyVisited.add(clazz);
String targetClassName = clazz.getName();
// always an Object.
if (clazz.isPrimitive()) {
Class<?> boxedType = JavaKind.fromJavaClass(clazz).toBoxedJavaClass();
registerIncludingAssociatedClasses(condition, boxedType, alreadyVisited);
return;
} else if (!Serializable.class.isAssignableFrom(clazz)) {
warn("Class " + targetClassName + " does not implement java.io.Serializable and was not registered for object serialization.\n");
return;
} else if (access.findSubclasses(clazz).size() > 1) {
// The classes returned from access.findSubclasses API including the base class itself
warn("Class " + targetClassName + " has subclasses. No classes were registered for object serialization.\n");
return;
}
try {
clazz.getDeclaredMethod("writeObject", ObjectOutputStream.class);
warn("Class " + targetClassName + " implements its own writeObject method for object serialization. Any serialization types it uses need to be explicitly registered.\n");
return;
} catch (NoSuchMethodException e) {
// Expected case. Do nothing
}
register(condition, clazz);
if (clazz.isArray()) {
registerIncludingAssociatedClasses(condition, clazz.getComponentType(), alreadyVisited);
return;
}
ObjectStreamClass osc = ObjectStreamClass.lookup(clazz);
try {
for (Object o : (Object[]) getDataLayoutMethod.invoke(osc)) {
ObjectStreamClass desc = (ObjectStreamClass) descField.get(o);
if (!desc.equals(osc)) {
registerIncludingAssociatedClasses(condition, desc.forClass(), alreadyVisited);
}
}
} catch (ReflectiveOperationException e) {
VMError.shouldNotReachHere("Cannot register serialization classes due to", e);
}
for (ObjectStreamField field : osc.getFields()) {
registerIncludingAssociatedClasses(condition, field.getType(), alreadyVisited);
}
}
Aggregations