Search in sources :

Example 41 with InvalidObjectException

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;
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) InvalidObjectException(java.io.InvalidObjectException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) ObjectInputStream(java.io.ObjectInputStream) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 42 with InvalidObjectException

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;
}
Also used : InvalidObjectException(java.io.InvalidObjectException) List(java.util.List) Point(java.awt.Point) Component(java.awt.Component) Point(java.awt.Point) ObjectInputStream(java.io.ObjectInputStream)

Example 43 with InvalidObjectException

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;
    }
}
Also used : InvalidObjectException(java.io.InvalidObjectException) IOException(java.io.IOException)

Example 44 with InvalidObjectException

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;
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Example 45 with InvalidObjectException

use of java.io.InvalidObjectException in project jdk8u_jdk by JetBrains.

the class HashMap method readObject.

/**
     * Reconstitute the {@code HashMap} instance from a stream (i.e.,
     * deserialize it).
     */
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in the threshold (ignored), loadfactor, and any hidden stuff
    s.defaultReadObject();
    reinitialize();
    if (loadFactor <= 0 || Float.isNaN(loadFactor))
        throw new InvalidObjectException("Illegal load factor: " + loadFactor);
    // Read and ignore number of buckets
    s.readInt();
    // Read number of mappings (size)
    int mappings = s.readInt();
    if (mappings < 0)
        throw new InvalidObjectException("Illegal mappings count: " + mappings);
    else if (mappings > 0) {
        // (if zero, use defaults)
        // Size the table using given load factor only if within
        // range of 0.25...4.0
        float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);
        float fc = (float) mappings / lf + 1.0f;
        int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ? DEFAULT_INITIAL_CAPACITY : (fc >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : tableSizeFor((int) fc));
        float ft = (float) cap * lf;
        threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? (int) ft : Integer.MAX_VALUE);
        @SuppressWarnings({ "rawtypes", "unchecked" }) Node<K, V>[] tab = (Node<K, V>[]) new Node[cap];
        table = tab;
        // Read the keys and values, and put the mappings in the HashMap
        for (int i = 0; i < mappings; i++) {
            @SuppressWarnings("unchecked") K key = (K) s.readObject();
            @SuppressWarnings("unchecked") V value = (V) s.readObject();
            putVal(hash(key), key, value, false, false);
        }
    }
}
Also used : InvalidObjectException(java.io.InvalidObjectException)

Aggregations

InvalidObjectException (java.io.InvalidObjectException)56 ObjectInputStream (java.io.ObjectInputStream)13 IOException (java.io.IOException)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Rational (android.util.Rational)5 GwtIncompatible (com.google.common.annotations.GwtIncompatible)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 GwtIncompatible (com.google_voltpatches.common.annotations.GwtIncompatible)2 Point (java.awt.Point)2 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 RemoteRef (java.rmi.server.RemoteRef)2 Comparator (java.util.Comparator)2 SimpleTimeZone (java.util.SimpleTimeZone)2 TimeZone (java.util.TimeZone)2 MBeanException (javax.management.MBeanException)2 OpenDataException (javax.management.openmbean.OpenDataException)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 ANTLRException (antlr.ANTLRException)1