-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2beta4
-
sparc
-
solaris_2.5
-
Verified
Name: avC70361 Date: 02/16/98
The java.util.mime.MimeType class cannot be de-externalized despite of
implementing java.io.Externalizable interface. This is because no-arg
constructor MimeType() has been removed from the class, but JLS for
java.io.Externalizable states that "When an Externalizable object is to be
reconstructed, an instance is created using the public no-arg constructor".
Therefore, during de-externalization no-arg constructor cannot be accesssd and
NoSuchMethod error is thrown.
Here is the test demonstrating the bug.
-------------MymeTypeTest.java------------
import java.util.mime.MimeType;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class MimeTypeTest {
public static void main(String args[]) {
MimeType mime = null;
ObjectOutputStream ostream = null;
ByteArrayOutputStream baos = null;
ObjectInputStream istream = null;
try {
mime = new MimeType("mime/sub");
ostream = new ObjectOutputStream(
baos = new ByteArrayOutputStream()
);
ostream.writeObject(mime);
ostream.flush();
} catch(Exception e) {
System.out.println("Unexpected exception while writing object : " + e);
System.exit(1);
}
try {
byte bytes[] = baos.toByteArray();
istream = new ObjectInputStream(new ByteArrayInputStream(bytes));
istream.readObject();
} catch(Exception e) {
System.out.println("Unexpected exception while reading object : " + e);
System.exit(1);
}
System.out.println("OK");
}
}
-----------The test output----------
> java MimeTypeTest
Unexpected exception while reading object : java.io.InvalidClassException: java.util.mime.MimeType; NoSuchMethodError accessing no-arg constructor
======================================================================