use of java.io.InvalidObjectException in project android_frameworks_base by ResurrectionRemix.
the class RationalTest method testSerialize.
@SmallTest
public void testSerialize() throws ClassNotFoundException, IOException {
/*
* Check correct [de]serialization
*/
assertEqualsAfterSerializing(ZERO);
assertEqualsAfterSerializing(NaN);
assertEqualsAfterSerializing(NEGATIVE_INFINITY);
assertEqualsAfterSerializing(POSITIVE_INFINITY);
assertEqualsAfterSerializing(UNIT);
assertEqualsAfterSerializing(new Rational(100, 200));
assertEqualsAfterSerializing(new Rational(-100, 200));
assertEqualsAfterSerializing(new Rational(5, 1));
assertEqualsAfterSerializing(new Rational(Integer.MAX_VALUE, Integer.MIN_VALUE));
/*
* Check bad deserialization fails
*/
try {
// [0, 100] , should be [0, 1]
Rational badZero = createIllegalRational(0, 100);
Rational results = serializeRoundTrip(badZero);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [100, 0] , should be [1, 0]
Rational badPosInfinity = createIllegalRational(100, 0);
Rational results = serializeRoundTrip(badPosInfinity);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
Rational badNegInfinity = // [-100, 0] , should be [-1, 0]
createIllegalRational(-100, 0);
Rational results = serializeRoundTrip(badNegInfinity);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [2,4] , should be [1, 2]
Rational badReduced = createIllegalRational(2, 4);
Rational results = serializeRoundTrip(badReduced);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [-2, 4] should be [-1, 2]
Rational badReducedNeg = createIllegalRational(-2, 4);
Rational results = serializeRoundTrip(badReducedNeg);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class DragSourceContext method readObject.
/**
* Deserializes this <code>DragSourceContext</code>. This method first
* performs default deserialization for all non-<code>transient</code>
* fields. This object's <code>Transferable</code> and
* <code>DragSourceListener</code> are then deserialized as well by using
* the next two objects in the stream. If the resulting
* <code>Transferable</code> is <code>null</code>, this object's
* <code>Transferable</code> is set to a dummy <code>Transferable</code>
* which supports no <code>DataFlavor</code>s.
*
* @since 1.4
*/
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
ObjectInputStream.GetField f = s.readFields();
DragGestureEvent newTrigger = (DragGestureEvent) f.get("trigger", null);
if (newTrigger == null) {
throw new InvalidObjectException("Null trigger");
}
if (newTrigger.getDragSource() == null) {
throw new InvalidObjectException("Null DragSource");
}
if (newTrigger.getComponent() == null) {
throw new InvalidObjectException("Null trigger component");
}
int newSourceActions = f.get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
if (newSourceActions == DnDConstants.ACTION_NONE) {
throw new InvalidObjectException("Invalid source actions");
}
int triggerActions = newTrigger.getDragAction();
if (triggerActions != DnDConstants.ACTION_COPY && triggerActions != DnDConstants.ACTION_MOVE && triggerActions != DnDConstants.ACTION_LINK) {
throw new InvalidObjectException("No drag action");
}
trigger = newTrigger;
cursor = (Cursor) f.get("cursor", null);
useCustomCursor = f.get("useCustomCursor", false);
sourceActions = newSourceActions;
transferable = (Transferable) s.readObject();
listener = (DragSourceListener) s.readObject();
// Implementation assumes 'transferable' is never null.
if (transferable == null) {
if (emptyTransferable == null) {
emptyTransferable = new Transferable() {
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[0];
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return false;
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
throw new UnsupportedFlavorException(flavor);
}
};
}
transferable = emptyTransferable;
}
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class DragGestureEvent method readObject.
/**
* Deserializes this <code>DragGestureEvent</code>. This method first
* performs default deserialization for all non-<code>transient</code>
* fields. An attempt is then made to deserialize this object's
* <code>List</code> of gesture events as well. This is first attempted
* by deserializing the field <code>events</code>, because, in releases
* prior to 1.4, a non-<code>transient</code> field of this name stored the
* <code>List</code> of gesture events. If this fails, the next object in
* the stream is used instead. If the resulting <code>List</code> is
* <code>null</code>, this object's <code>List</code> of gesture events
* is set to an empty <code>List</code>.
*
* @since 1.4
*/
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
ObjectInputStream.GetField f = s.readFields();
DragSource newDragSource = (DragSource) f.get("dragSource", null);
if (newDragSource == null) {
throw new InvalidObjectException("null DragSource");
}
dragSource = newDragSource;
Component newComponent = (Component) f.get("component", null);
if (newComponent == null) {
throw new InvalidObjectException("null component");
}
component = newComponent;
Point newOrigin = (Point) f.get("origin", null);
if (newOrigin == null) {
throw new InvalidObjectException("null origin");
}
origin = newOrigin;
int newAction = f.get("action", 0);
if (newAction != DnDConstants.ACTION_COPY && newAction != DnDConstants.ACTION_MOVE && newAction != DnDConstants.ACTION_LINK) {
throw new InvalidObjectException("bad action");
}
action = newAction;
// Pre-1.4 support. 'events' was previously non-transient
List newEvents;
try {
newEvents = (List) f.get("events", null);
} catch (IllegalArgumentException e) {
// 1.4-compatible byte stream. 'events' was written explicitly
newEvents = (List) s.readObject();
}
// Implementation assumes 'events' is never null.
if (newEvents != null && newEvents.isEmpty()) {
// Throw exception if serialized list is empty
throw new InvalidObjectException("empty list of events");
} else if (newEvents == null) {
newEvents = Collections.emptyList();
}
events = newEvents;
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class URI method readObject.
/**
* Reconstitutes a URI from the given serial stream.
*
* <p> The {@link java.io.ObjectInputStream#defaultReadObject()} method is
* invoked to read the value of the {@code string} field. The result is
* then parsed in the usual way.
*
* @param is The object-input stream from which this object
* is being read
*/
private void readObject(ObjectInputStream is) throws ClassNotFoundException, IOException {
// Argh
port = -1;
is.defaultReadObject();
try {
new Parser(string).parse(false);
} catch (URISyntaxException x) {
IOException y = new InvalidObjectException("Invalid URI");
y.initCause(x);
throw y;
}
}
use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.
the class UrlDeserializedState method fabricateNewURL.
private URL fabricateNewURL() throws InvalidObjectException {
// create URL string from deserialized object
URL replacementURL = null;
String urlString = tempState.reconstituteUrlString();
try {
replacementURL = new URL(urlString);
} catch (MalformedURLException mEx) {
resetState();
InvalidObjectException invoEx = new InvalidObjectException("Malformed URL: " + urlString);
invoEx.initCause(mEx);
throw invoEx;
}
replacementURL.setSerializedHashCode(tempState.getHashCode());
resetState();
return replacementURL;
}
Aggregations