use of java.io.ObjectStreamField in project wicket by apache.
the class CheckingObjectOutputStream method checkFields.
private void checkFields(Object obj, ObjectStreamClass desc) {
int numFields;
try {
numFields = (Integer) GET_NUM_OBJ_FIELDS_METHOD.invoke(desc, (Object[]) null);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
if (numFields > 0) {
int numPrimFields;
ObjectStreamField[] fields = desc.getFields();
Object[] objVals = new Object[numFields];
numPrimFields = fields.length - objVals.length;
try {
GET_OBJ_FIELD_VALUES_METHOD.invoke(desc, obj, objVals);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < objVals.length; i++) {
if (objVals[i] instanceof String || objVals[i] instanceof Number || objVals[i] instanceof Date || objVals[i] instanceof Boolean || objVals[i] instanceof Class) {
// filter out common cases
continue;
}
// Check for circular reference.
if (checked.containsKey(objVals[i])) {
continue;
}
ObjectStreamField fieldDesc = fields[numPrimFields + i];
Field field;
try {
field = (Field) GET_FIELD_METHOD.invoke(fieldDesc, (Object[]) null);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
simpleName = field.getName();
fieldDescription = field.toString();
check(objVals[i]);
}
}
}
use of java.io.ObjectStreamField in project j2objc by google.
the class ObjectStreamClassTest method test_specialTypes.
public void test_specialTypes() {
Class<?> proxyClass = Proxy.getProxyClass(this.getClass().getClassLoader(), new Class[] { Runnable.class });
ObjectStreamClass proxyStreamClass = ObjectStreamClass.lookup(proxyClass);
assertEquals("Proxy classes should have zero serialVersionUID", 0, proxyStreamClass.getSerialVersionUID());
ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
assertEquals("Proxy classes should have no serialized fields", 0, proxyFields.length);
ObjectStreamClass enumStreamClass = ObjectStreamClass.lookup(Thread.State.class);
assertEquals("Enum classes should have zero serialVersionUID", 0, enumStreamClass.getSerialVersionUID());
ObjectStreamField[] enumFields = enumStreamClass.getFields();
assertEquals("Enum classes should have no serialized fields", 0, enumFields.length);
}
use of java.io.ObjectStreamField in project j2objc by google.
the class MyObjectInputStream method test_getType_Deserialized.
/**
* java.io.ObjectStreamField#getType()
*/
public void test_getType_Deserialized() throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(new SerializableObject());
oos.close();
baos.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
SerializableObject obj = (SerializableObject) ois.readObject();
ObjectStreamClass oc = obj.getObjectStreamClass();
ObjectStreamField field = oc.getField("i");
assertEquals(Object.class, field.getType());
}
use of java.io.ObjectStreamField in project j2objc by google.
the class OldObjectStreamFieldTest method test_ConstructorLjava_lang_StringLjava_lang_ClassB.
public void test_ConstructorLjava_lang_StringLjava_lang_ClassB() {
ObjectStreamField osf = new ObjectStreamField("aField", int.class, false);
assertTrue("Test 1: Name member not set correctly.", osf.getName().equals("aField"));
assertTrue("Test 2: Type member not set correctly.", osf.getType().equals(int.class));
assertFalse("Test 3: Unshared member not set correctly.", osf.isUnshared());
// Repeat the tests with a different object to make sure
// that we have not tested against default values.
osf = new ObjectStreamField("anotherField", String.class, true);
assertTrue("Test 4: Name member not set correctly.", osf.getName().equals("anotherField"));
assertTrue("Test 5: Type member not set correctly.", osf.getType().equals(String.class));
assertTrue("Test 6: Unshared member not set correctly.", osf.isUnshared());
// Invalid argument tests.
try {
osf = new ObjectStreamField(null, boolean.class);
fail("Test 7: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected.
}
try {
osf = new ObjectStreamField("thisField", null);
fail("Test 8: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected.
}
}
use of java.io.ObjectStreamField in project robovm by robovm.
the class OldObjectStreamFieldTest method test_ConstructorLjava_lang_StringLjava_lang_Class.
public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
ObjectStreamField osf = new ObjectStreamField("aField", int.class);
assertTrue("Test 1: Name member not set correctly.", osf.getName().equals("aField"));
assertTrue("Test 2: Type member not set correctly.", osf.getType().equals(int.class));
// Repeat the tests with a different object to make sure
// that we have not tested against default values.
osf = new ObjectStreamField("anotherField", String.class);
assertTrue("Test 3: Name member not set correctly.", osf.getName().equals("anotherField"));
assertTrue("Test 4: Type member not set correctly.", osf.getType().equals(String.class));
// Invalid argument tests.
try {
osf = new ObjectStreamField(null, boolean.class);
fail("Test 5: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected.
}
try {
osf = new ObjectStreamField("thisField", null);
fail("Test 6: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected.
}
}
Aggregations