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/10/22 18:48:50 UTC

[jira] Created: (HARMONY-4996) [classlib][luni] Incorrect deserialization of Externalizable classes

[classlib][luni] Incorrect deserialization of Externalizable classes
--------------------------------------------------------------------

                 Key: HARMONY-4996
                 URL: https://issues.apache.org/jira/browse/HARMONY-4996
             Project: Harmony
          Issue Type: Bug
          Components: App-Oriented Bug Reports, Classlib
         Environment: Win XP
            Reporter: Mikhail Markov
            Assignee: Mikhail Markov


The testcase below passed on RI but failed on Harmony with the following stacktrace:
java.io.StreamCorruptedException: Wrong format: 0x0
        at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:842)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2128)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:283)
        at Test.main(Test.java:18)

--------------------------- Test.java --------------------------------
import java.io.*;

public class Test {
    static ObjectStreamClass[] objs = new ObjectStreamClass[1000];
    static int pos = 0;

    public static void main(String[] args) {
        try {
            PipedOutputStream pout = new PipedOutputStream();
            PipedInputStream pin = new PipedInputStream(pout);
            ObjectOutputStream oout = new TestObjectOutputStream(pout);
            oout.writeObject(new TestExtObject());
            oout.writeObject("test");
            oout.close();
            pos = 0;
            ObjectInputStream oin = new TestObjectInputStream(pin);
            oin.readObject();
            oin.readObject();
            System.out.println("Done.");
        } catch (Exception ex) { 
            ex.printStackTrace();
        }
    }

    public static class TestExtObject implements Externalizable {
        public void writeExternal(ObjectOutput out) throws IOException {
            out.writeInt(10);
        }

        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
            in.readInt();
        }
    }

    static class TestObjectOutputStream extends ObjectOutputStream {
        public TestObjectOutputStream(OutputStream out) throws IOException {
            super(out);
        }

        protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException {
            objs[pos++] = osc;        }
    }

    static class TestObjectInputStream extends ObjectInputStream {
        public TestObjectInputStream(InputStream in) throws IOException {
            super(in);
        }

        protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
            return (ObjectStreamClass) objs[pos++];
        }
    }
}
-------------------------------------------------------------------------

This test actually saves the incoming ObjectStreamClass-es in local array and does not write them to ObjectOutputStream (and takes them from this array in de-serialization). It seems like Externalizable class does not properly de-serialized as the exception occured during the next readObject() call.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-4996) [classlib][luni] Incorrect deserialization of Externalizable classes

Posted by "Mikhail Markov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-4996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12536742 ] 

Mikhail Markov commented on HARMONY-4996:
-----------------------------------------

I've investigated the issue and found that the described effect happens due to differences in protocol versions 1 & 2. In the test above the following sequence took place (looking into the Harmony code):
1) ObjectStreamClass for externalizable TestExtObject is created - by default it has flags set to ObjectStreamConstants.SC_EXTERNALIZABLE
2) This object is serialized to the stream using verion 2 of the protocal (by default)
3) When this object is de-serialized from the stream, as it's ObjectStreamClass does not de-serialized from the stream, but the one created in the 1-st step is used instead, it has no indication that it's using version 2, so version 1 is used and although the de-serialization of TestExtObject is completed, the serialization procedure is broken so next attempt to read an object from this stream leads to the mentioned exception

I'm working on the issue and hopefully will provide a patch soon.


> [classlib][luni] Incorrect deserialization of Externalizable classes
> --------------------------------------------------------------------
>
>                 Key: HARMONY-4996
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4996
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>            Assignee: Mikhail Markov
>
> The testcase below passed on RI but failed on Harmony with the following stacktrace:
> java.io.StreamCorruptedException: Wrong format: 0x0
>         at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:842)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2128)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:283)
>         at Test.main(Test.java:18)
> --------------------------- Test.java --------------------------------
> import java.io.*;
> public class Test {
>     static ObjectStreamClass[] objs = new ObjectStreamClass[1000];
>     static int pos = 0;
>     public static void main(String[] args) {
>         try {
>             PipedOutputStream pout = new PipedOutputStream();
>             PipedInputStream pin = new PipedInputStream(pout);
>             ObjectOutputStream oout = new TestObjectOutputStream(pout);
>             oout.writeObject(new TestExtObject());
>             oout.writeObject("test");
>             oout.close();
>             pos = 0;
>             ObjectInputStream oin = new TestObjectInputStream(pin);
>             oin.readObject();
>             oin.readObject();
>             System.out.println("Done.");
>         } catch (Exception ex) { 
>             ex.printStackTrace();
>         }
>     }
>     public static class TestExtObject implements Externalizable {
>         public void writeExternal(ObjectOutput out) throws IOException {
>             out.writeInt(10);
>         }
>         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
>             in.readInt();
>         }
>     }
>     static class TestObjectOutputStream extends ObjectOutputStream {
>         public TestObjectOutputStream(OutputStream out) throws IOException {
>             super(out);
>         }
>         protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException {
>             objs[pos++] = osc;        }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         public TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
>             return (ObjectStreamClass) objs[pos++];
>         }
>     }
> }
> -------------------------------------------------------------------------
> This test actually saves the incoming ObjectStreamClass-es in local array and does not write them to ObjectOutputStream (and takes them from this array in de-serialization). It seems like Externalizable class does not properly de-serialized as the exception occured during the next readObject() call.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (HARMONY-4996) [classlib][luni] Incorrect deserialization of Externalizable classes

Posted by "Mikhail Markov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-4996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mikhail Markov closed HARMONY-4996.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 5.0M4

Fix applied at r601490.

> [classlib][luni] Incorrect deserialization of Externalizable classes
> --------------------------------------------------------------------
>
>                 Key: HARMONY-4996
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4996
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>            Assignee: Mikhail Markov
>             Fix For: 5.0M4
>
>         Attachments: H-4996.patch
>
>
> The testcase below passed on RI but failed on Harmony with the following stacktrace:
> java.io.StreamCorruptedException: Wrong format: 0x0
>         at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:842)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2128)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:283)
>         at Test.main(Test.java:18)
> --------------------------- Test.java --------------------------------
> import java.io.*;
> public class Test {
>     static ObjectStreamClass[] objs = new ObjectStreamClass[1000];
>     static int pos = 0;
>     public static void main(String[] args) {
>         try {
>             PipedOutputStream pout = new PipedOutputStream();
>             PipedInputStream pin = new PipedInputStream(pout);
>             ObjectOutputStream oout = new TestObjectOutputStream(pout);
>             oout.writeObject(new TestExtObject());
>             oout.writeObject("test");
>             oout.close();
>             pos = 0;
>             ObjectInputStream oin = new TestObjectInputStream(pin);
>             oin.readObject();
>             oin.readObject();
>             System.out.println("Done.");
>         } catch (Exception ex) { 
>             ex.printStackTrace();
>         }
>     }
>     public static class TestExtObject implements Externalizable {
>         public void writeExternal(ObjectOutput out) throws IOException {
>             out.writeInt(10);
>         }
>         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
>             in.readInt();
>         }
>     }
>     static class TestObjectOutputStream extends ObjectOutputStream {
>         public TestObjectOutputStream(OutputStream out) throws IOException {
>             super(out);
>         }
>         protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException {
>             objs[pos++] = osc;        }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         public TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
>             return (ObjectStreamClass) objs[pos++];
>         }
>     }
> }
> -------------------------------------------------------------------------
> This test actually saves the incoming ObjectStreamClass-es in local array and does not write them to ObjectOutputStream (and takes them from this array in de-serialization). It seems like Externalizable class does not properly de-serialized as the exception occured during the next readObject() call.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-4996) [classlib][luni] Incorrect deserialization of Externalizable classes

Posted by "Mikhail Markov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-4996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mikhail Markov updated HARMONY-4996:
------------------------------------

    Attachment: H-4996.patch

Here is the patch fixing the issue.

> [classlib][luni] Incorrect deserialization of Externalizable classes
> --------------------------------------------------------------------
>
>                 Key: HARMONY-4996
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4996
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>            Assignee: Mikhail Markov
>         Attachments: H-4996.patch
>
>
> The testcase below passed on RI but failed on Harmony with the following stacktrace:
> java.io.StreamCorruptedException: Wrong format: 0x0
>         at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:842)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2128)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:283)
>         at Test.main(Test.java:18)
> --------------------------- Test.java --------------------------------
> import java.io.*;
> public class Test {
>     static ObjectStreamClass[] objs = new ObjectStreamClass[1000];
>     static int pos = 0;
>     public static void main(String[] args) {
>         try {
>             PipedOutputStream pout = new PipedOutputStream();
>             PipedInputStream pin = new PipedInputStream(pout);
>             ObjectOutputStream oout = new TestObjectOutputStream(pout);
>             oout.writeObject(new TestExtObject());
>             oout.writeObject("test");
>             oout.close();
>             pos = 0;
>             ObjectInputStream oin = new TestObjectInputStream(pin);
>             oin.readObject();
>             oin.readObject();
>             System.out.println("Done.");
>         } catch (Exception ex) { 
>             ex.printStackTrace();
>         }
>     }
>     public static class TestExtObject implements Externalizable {
>         public void writeExternal(ObjectOutput out) throws IOException {
>             out.writeInt(10);
>         }
>         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
>             in.readInt();
>         }
>     }
>     static class TestObjectOutputStream extends ObjectOutputStream {
>         public TestObjectOutputStream(OutputStream out) throws IOException {
>             super(out);
>         }
>         protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException {
>             objs[pos++] = osc;        }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         public TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
>             return (ObjectStreamClass) objs[pos++];
>         }
>     }
> }
> -------------------------------------------------------------------------
> This test actually saves the incoming ObjectStreamClass-es in local array and does not write them to ObjectOutputStream (and takes them from this array in de-serialization). It seems like Externalizable class does not properly de-serialized as the exception occured during the next readObject() call.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.