Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6692027
Votes 0
Synopsis REGRESSION: Custom subclasses of QueryEval don't serialize
Category jmx:classes
Reported Against
Release Fixed 7(b27)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs
Submit Date 22-APR-2008
Description
With recent builds of JDK 7, a user subclass of javax.management.QueryEval will no longer
serialize.  The following test program:

import java.io.*;
import javax.management.*;

public class QES extends QueryEval {
    public static void main(String[] args) throws Exception {
	QES qes = new QES();
    	ByteArrayOutputStream bout = new ByteArrayOutputStream();
	ObjectOutputStream oout = new ObjectOutputStream(bout);
	oout.writeObject(qes);
	oout.close();
	ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
	ObjectInputStream oin = new ObjectInputStream(bin);
	QES qes2 = (QES) oin.readObject();
	System.out.println("Read: " + qes2);
    }
}

produces the following exception:

Exception in thread "main" java.io.InvalidClassException: QES; QES; no valid constructor
	at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:730)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
	at QES.main(QES.java:13)
Caused by: java.io.InvalidClassException: QES; no valid constructor
	at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:488)
	at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:327)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1123)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)
	at QES.main(QES.java:9)
Posted Date : 2008-04-22 14:32:05.0
Work Around
N/A
Evaluation
This is due to the new non-public class javax.management.ToQueryString, which defines a toQueryString() method that is overridden by various other javax.management classes.  Serialization requires the first non-serializable superclass of the serialized class to have a no-arg constructor that is accessible to the serialized class.  A custom subclass will be outside the javax.management package so will not have access to the constructor of javax.management.ToQueryString.  It happens that adding a public constructor to ToQueryString will fix this problem, but that is arguably a bug in the serialization system so we should not rely on it.  We will need to rewrite the code to dispense with ToQueryString, which will probably require an ugly chain of "if instanceof".
Posted Date : 2008-04-22 14:32:05.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang