harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Markov (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-1920) [classlib][luni] class replacement in ObjectInputStream.resolveClass() should not work for different class names
Date Thu, 19 Oct 2006 14:22:34 GMT
[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

        

Mime
View raw message