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 2007/01/09 14:05:27 UTC

[jira] Commented: (HARMONY-1921) [classlib][luni] improper class replacement for the same base class names in ObjectInputStream.resolveClass()

    [ https://issues.apache.org/jira/browse/HARMONY-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12463267 ] 

Mikhail Markov commented on HARMONY-1921:
-----------------------------------------

Thanks, Tim! Everything works now.

> [classlib][luni] improper class replacement for the same base class names in ObjectInputStream.resolveClass()
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1921
>                 URL: https://issues.apache.org/jira/browse/HARMONY-1921
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: IA32, WinXP
>            Reporter: Mikhail Markov
>         Assigned To: Tim Ellison
>         Attachments: H-1921-impl.patch, H-1921-test.patch
>
>
> Object serialization specification states that starting from JDK 1.6 method resolveClass in ObjectInputStream class could return a class with the same *base* class name (but, possibly from another package) and SerialVersionUID as the class provided for replacement. In this case the fields of replacement class should be initialized by the ones of original class from the stream. 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 {
>         a.TestClass to1 = new a.TestClass();
>         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 {
>             b.TestClass to2 = (b.TestClass) ois.readObject();
>             if (to2.i != to1.i) {
>                 System.out.println("Test failed. Expected: " + to1.i + ", got: " + to2.i);
>             } else {
>                 System.out.println("Test passed.");
>             }
>         } catch (InvalidClassException ice) {
>             System.out.println("Test failed with exception: " + ice);
>         }
>     }
>     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("a.TestClass")) {
>                 return b.TestClass.class;
>             }
>             return super.resolveClass(desc);
>         }
>     }
> }
> -----------------------------------------------------------------
> ------------------------- a/TestClass.java -----------------------------
> package a;
> import java.io.Serializable;
> public class TestClass implements Serializable {
>     private static final long serialVersionUID = 11111L;
>     public int i = 0;
> }
> -----------------------------------------------------------------
> ------------------------- b/TestClass.java -----------------------------
> package b;
> import java.io.Serializable;
> public class TestClass implements Serializable {
>     private static final long serialVersionUID = 11111L;
>     public int i = 0;
> }
> -----------------------------------------------------------------
> Output on RI:
> Test passed.
> Output on Harmony:
> Test failed. Expected: 555, got: 0

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira