-
Bug
-
Resolution: Fixed
-
P3
-
1.2.2, 1.3.1_01
-
03
-
x86, sparc
-
solaris_2.6, windows_nt
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2027725 | 1.4.0 | Anne Fowler | P3 | Resolved | Fixed | beta |
Name: sg39081 Date: 06/23/99
The EventListenerList.readMethod() throws ClassNotFoundExceptions
when an EventListenerList object is serialized, under the following
circumstances:
a.) listeners added to the EventListenerList object aren't anonymous.
b.) listeners added to the EventListenerList object don't
come as part of the API, such as ActionListener.
An example which demonstrates the problem is below;
the stack trace, after running it, is as follows:
java.lang.ClassNotFoundException: MyListener
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java, Compiled Code)
at javax.swing.event.EventListenerList.readObject(EventListenerList.java, Compiled Code)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java, Compiled Code)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java, Compiled Code)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java, Compiled Code)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java, Compiled Code)
at A.copyObject(A.java, Compiled Code)
at A.<init>(A.java, Compiled Code)
at A.main(A.java, Compiled Code)
//File -- A.java
//
import java.io.*;
import java.util.EventListener;
import javax.swing.event.EventListenerList;
interface MyListener extends EventListener{}
public class A implements MyListener, EventListener, Serializable
{
public A()
{
EventListenerList listenerList = new EventListenerList();
try
{
//Using base EventListener for the the class type parameter
//and a non anonymous class for the listener
listenerList.add(EventListener.class, this);
//This will serialize without a problem.
copyObject(listenerList);
//Using sub interface of EventListener for the the class type parameter
//and a anonymous class for the listener
listenerList.add(MyListener.class, new MyListener(){});
//This will serialize without a problem.
copyObject(listenerList);
//Using sub interface of EventListener for the the class type parameter
//and a non anonymous class for the listener
listenerList.add(MyListener.class, this);
//The call to copyObject() below will cause a ClassNotFoundException exception.
copyObject(listenerList);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
/**
* Makes a copy of an object, using serialization.
*
* @param o source object
* @return copy of of the source object.
*/
synchronized static public Object copyObject(final Object o)
throws ClassNotFoundException, IOException, StreamCorruptedException
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutput os = new ObjectOutputStream(baos);
os.writeObject(o);
os.flush();
os.close();
baos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInput is = new ObjectInputStream(bais);
return is.readObject();
}
public static void main(String args[] )
{
A a = new A();
}
}
//
//File -- A.java
(Review ID: 55295)
======================================================================
- backported by
-
JDK-2027725 Serializing EventListenerList causes ClassNotFound exceptions
- Resolved
- duplicates
-
JDK-4533735 RMI - passing object by value results in Unmarshalling exception (JDK 1.3.1_01)
- Closed