You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Mikhail Markov (JIRA)" <ji...@apache.org> on 2006/10/19 16:49:36 UTC
[jira] Commented: (HARMONY-1920) [classlib][luni] class replacement
in ObjectInputStream.resolveClass() should not work for different class
names
[ http://issues.apache.org/jira/browse/HARMONY-1920?page=comments#action_12443543 ]
Mikhail Markov commented on HARMONY-1920:
-----------------------------------------
Error in JDK version: should be JDK1.1.6 :-)
> [classlib][luni] class replacement in ObjectInputStream.resolveClass() should not work for different class names
> ----------------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-1920
> URL: http://issues.apache.org/jira/browse/HARMONY-1920
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Environment: IA32, Win XP
> Reporter: Mikhail Markov
>
> Object serialization specification states that starting from JDK 1.6 method resolveClass in ObjectInputStream class should to return a class with at least the same *base* class name and SerialVersionUID as the class provided for replacement. The following test passes on RI but fails on Harmony:
> ------------------------- Test.java -----------------------------
> import java.io.*;
> public class Test {
> public static void main(String[] args) throws Exception {
> TestClass1 to1 = new TestClass1();
> to1.i = 555;
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(baos);
> oos.writeObject(to1);
> oos.flush();
> byte[] bytes = baos.toByteArray();
> ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
> ObjectInputStream ois = new TestObjectInputStream(bais);
> try {
> TestClass2 to2 = (TestClass2) ois.readObject();
> System.out.println("Test failed.");
> } catch (InvalidClassException ice) {
> System.out.println("Test passed.");
> }
> }
> static class TestObjectInputStream extends ObjectInputStream {
> public TestObjectInputStream(InputStream in) throws IOException {
> super(in);
> }
>
> protected Class resolveClass(ObjectStreamClass desc)
> throws IOException, ClassNotFoundException {
> if (desc.getName().equals("Test$TestClass1")) {
> return TestClass2.class;
> }
> return super.resolveClass(desc);
> }
> }
> static class TestClass1 implements Serializable {
> private static final long serialVersionUID = 11111L;
> int i = 0;
> }
> static class TestClass2 implements Serializable {
> private static final long serialVersionUID = 11111L;
> int i = 0;
> }
> }
> -----------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira