Search in sources :

Example 11 with NotSerializableException

use of java.io.NotSerializableException in project midpoint by Evolveum.

the class PropertySimpleValueFilterType 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;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 12 with NotSerializableException

use of java.io.NotSerializableException in project midpoint by Evolveum.

the class SearchFilterType 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;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 13 with NotSerializableException

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

the class PinLastArguments method main.

public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6332349\n");
    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }
    System.err.println("TEST PASSED");
}
Also used : MarshalException(java.rmi.MarshalException) NotSerializableException(java.io.NotSerializableException) WeakReference(java.lang.ref.WeakReference) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject)

Example 14 with NotSerializableException

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

the class NotSerializable method main.

public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 4460983\n");
    Activatable act = new FakeActivatable();
    try {
        ObjectOutputStream out = new ObjectOutputStream(new ByteArrayOutputStream());
        try {
            out.writeObject(act);
            throw new RuntimeException("TEST FAILED: " + "Activatable instance successfully serialized");
        } catch (NotSerializableException e) {
            System.err.println("NotSerializableException as expected:");
            e.printStackTrace();
        }
        // other exceptions cause test failure
        System.err.println("TEST PASSED");
    } finally {
        try {
            Activatable.unexportObject(act, true);
        } catch (NoSuchObjectException e) {
        }
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) Activatable(java.rmi.activation.Activatable) NoSuchObjectException(java.rmi.NoSuchObjectException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 15 with NotSerializableException

use of java.io.NotSerializableException in project opennms by OpenNMS.

the class TrapNotificationSerializationTest method writeTrapNotificationObject.

public boolean writeTrapNotificationObject(TrapInformation object) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
        objectOutputStream.writeObject(object);
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
        TrapInformation notification = (TrapInformation) in.readObject();
    } catch (NotSerializableException e) {
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    return false;
}
Also used : NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) TrapInformation(org.opennms.netmgt.snmp.TrapInformation)

Aggregations

NotSerializableException (java.io.NotSerializableException)39 ObjectOutputStream (java.io.ObjectOutputStream)14 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectInputStream (java.io.ObjectInputStream)9 Test (org.junit.Test)9 Person (com.alibaba.dubbo.common.model.Person)7 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)7 ArrayList (java.util.ArrayList)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)5 InvalidClassException (java.io.InvalidClassException)4 OptionalDataException (java.io.OptionalDataException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3