use of java.io.InvalidClassException in project jdk8u_jdk by JetBrains.
the class CheckInputOrderTest method testRejectedInGlobal.
/**
* Test:
* "global filter reject" + "specific ObjectInputStream filter is empty" => should reject
* "global filter reject" + "specific ObjectInputStream filter allow" => should allow
*/
@Test(dataProvider = "Patterns")
public void testRejectedInGlobal(Object toDeserialized, String pattern, boolean allowed) throws Exception {
byte[] bytes = SerialFilterTest.writeObjects(toDeserialized);
ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais)) {
ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
Object o = ois.readObject();
assertTrue(allowed, "filter should have thrown an exception");
} catch (InvalidClassException ice) {
assertFalse(allowed, "filter should have thrown an exception");
}
}
use of java.io.InvalidClassException in project jdk8u_jdk by JetBrains.
the class MixedFiltersTest method testAllowedInGlobal.
/**
* Test:
* "global filter allow" + "specific ObjectInputStream filter is empty" => should allow
* "global filter allow" + "specific ObjectInputStream filter reject" => should reject
*/
@Test(dataProvider = "AllowedInGlobal")
public void testAllowedInGlobal(Object toDeserialized, String pattern) throws Exception {
byte[] bytes = SerialFilterTest.writeObjects(toDeserialized);
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais)) {
Object o = ois.readObject();
}
ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais)) {
ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
Object o = ois.readObject();
assertTrue(false, "filter should have thrown an exception");
} catch (InvalidClassException expected) {
}
}
use of java.io.InvalidClassException in project jdk8u_jdk by JetBrains.
the class XPathExceptionInitCause method main.
public static void main(String[] args) throws Exception {
Throwable cause = new Throwable("message 1");
XPathException xpathexcep = new XPathException("message 2");
//Test XPE initCause() method
xpathexcep.initCause(cause);
System.out.println("getCause() result: '" + xpathexcep.getCause() + "' Cause itself: '" + cause + "'");
if (!xpathexcep.getCause().toString().equals(cause.toString())) {
throw new Exception("Incorrect cause is set by initCause()");
}
//Test serialization/deserialization of initialized XPE
byte[] xpeserial;
XPathException xpedeser;
xpeserial = pickleXPE(xpathexcep);
xpedeser = unpickleXPE(xpeserial);
System.out.println("Serialized XPE: message='" + xpathexcep.getMessage() + "' cause='" + xpathexcep.getCause().toString() + "'");
System.out.println("Deserialized XPE: message='" + xpedeser.getMessage() + "' cause='" + xpedeser.getCause().toString() + "'");
if (xpedeser.getCause() == null || !xpedeser.getCause().toString().equals(cause.toString()) || !xpedeser.getMessage().toString().equals("message 2"))
throw new Exception("XPathException incorrectly serialized/deserialized");
//Test serialization/deserialization of uninitialized cause in XPE
XPathException xpeuninit = new XPathException("uninitialized cause");
xpeserial = pickleXPE(xpeuninit);
xpedeser = unpickleXPE(xpeserial);
System.out.println("Serialized XPE: message='" + xpeuninit.getMessage() + "' cause='" + xpeuninit.getCause() + "'");
System.out.println("Deserialized XPE: message='" + xpedeser.getMessage() + "' cause='" + xpedeser.getCause() + "'");
if (xpedeser.getCause() != null || !xpedeser.getMessage().toString().equals("uninitialized cause"))
throw new Exception("XPathException incorrectly serialized/deserialized");
//Test deserialization of normal XPathException serialized by JDK7
XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
if (xpejdk7 == null || xpejdk7.getCause() == null || !xpejdk7.getMessage().equals("message 2") || !xpejdk7.getCause().getMessage().equals("message 1"))
throw new Exception("XpathException serialized by JDK7 was " + "incorrectly deserialized.");
// new XPathException(new Exception()).initCause(null)
try {
xpejdk7 = unpickleXPE(TWOCAUSES);
throw new Exception("Expected InvalidClassException but it wasn't" + " observed");
} catch (InvalidClassException e) {
System.out.println("InvalidClassException caught as expected.");
}
}
use of java.io.InvalidClassException in project midpoint by Evolveum.
the class PropertyComplexValueFilterType method copyOf.
/**
* Creates and returns a deep copy of a given {@code Serializable}.
*
* @param serializable
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
*/
private static Serializable copyOf(final Serializable serializable) {
// CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
if (serializable != null) {
try {
final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
out.writeObject(serializable);
out.close();
final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
final Serializable copy = ((Serializable) in.readObject());
in.close();
return copy;
} catch (SecurityException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (ClassNotFoundException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (InvalidClassException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (NotSerializableException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (StreamCorruptedException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (OptionalDataException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (IOException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
}
}
return null;
}
use of java.io.InvalidClassException in project midpoint by Evolveum.
the class QueryType method copyOf.
/**
* Creates and returns a deep copy of a given {@code Serializable}.
*
* @param serializable
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
*/
private static Serializable copyOf(final Serializable serializable) {
// CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
if (serializable != null) {
try {
final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
out.writeObject(serializable);
out.close();
final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
final Serializable copy = ((Serializable) in.readObject());
in.close();
return copy;
} catch (SecurityException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (ClassNotFoundException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (InvalidClassException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (NotSerializableException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (StreamCorruptedException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (OptionalDataException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (IOException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
}
}
return null;
}
Aggregations