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/08/16 10:33:31 UTC

[jira] Created: (HARMONY-4638) [classlib][luni] ObjectStreamClass.lookup() incorrectly works

[classlib][luni] ObjectStreamClass.lookup() incorrectly works
-------------------------------------------------------------

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


ObjectStreamClass.lookup() method returns incorrect ObjectStreamClass, which could not be used for replacement in ObjectInputStream.readClassDescriptor(). The test below demonstrates the problem.
Output on RI: Passed
Output on Harmony: FAILED: expected - It's a test, but got - null

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

public class Test implements Serializable {
    public String str;

    public static void main(String[] args) throws Exception {
        Test t = new Test();
        t.str = "It's a test";
        PipedOutputStream pout = new PipedOutputStream();
        PipedInputStream pin = new PipedInputStream(pout);
        ObjectOutputStream out = new ObjectOutputStream(pout);
        TestObjectInputStream in = new TestObjectInputStream(pin);
        out.writeObject(t);
        Test t1 = (Test) in.readObject();

        if (!t.str.equals(t1.str)) {
            System.out.println("FAILED: expected - " + t.str + ", but got - " + t1.str);
        } else {
            System.out.println("PASSED.");
        }
    }

    static class TestObjectInputStream extends ObjectInputStream {
        private static ObjectStreamClass testOsc = ObjectStreamClass.lookup(Test.class);

        TestObjectInputStream(InputStream in) throws IOException {
            super(in);
        }

        protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException {
            ObjectStreamClass osc = super.readClassDescriptor();

            if(osc.getName().equals("Test")) {
                return testOsc;
            }
            return osc;
        }
    }
}
-------------------------

I've investigated the problem a bit and found that ObjectStreamClass has package-protected method getLoadFields() which is used by ObjectInputStream to get an array of ObjectStreaFields-s to be loaded from the stream in case of default de-serialization. For ObjectStreamClass created by ObjectStreamClass.lookup() method, this method returns an empty array, thus in case of default de-serialization ObjectInputStream does not try to read any field value from the stream - although there are data to be read in the stream.

I'll provide a patch soon.

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


[jira] Resolved: (HARMONY-4638) [classlib][luni] ObjectStreamClass.lookup() incorrectly works

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

Tim Ellison resolved HARMONY-4638.
----------------------------------

    Resolution: Fixed

Thanks Mikhail.

Patch applied to LUNI module at repo revision r569151.

Please check it was applied as you expected.


> [classlib][luni] ObjectStreamClass.lookup() incorrectly works
> -------------------------------------------------------------
>
>                 Key: HARMONY-4638
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4638
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>            Assignee: Tim Ellison
>         Attachments: H-4638.patch
>
>
> ObjectStreamClass.lookup() method returns incorrect ObjectStreamClass, which could not be used for replacement in ObjectInputStream.readClassDescriptor(). The test below demonstrates the problem.
> Output on RI: Passed
> Output on Harmony: FAILED: expected - It's a test, but got - null
> --------- Test.java -----------
> import java.io.*;
> public class Test implements Serializable {
>     public String str;
>     public static void main(String[] args) throws Exception {
>         Test t = new Test();
>         t.str = "It's a test";
>         PipedOutputStream pout = new PipedOutputStream();
>         PipedInputStream pin = new PipedInputStream(pout);
>         ObjectOutputStream out = new ObjectOutputStream(pout);
>         TestObjectInputStream in = new TestObjectInputStream(pin);
>         out.writeObject(t);
>         Test t1 = (Test) in.readObject();
>         if (!t.str.equals(t1.str)) {
>             System.out.println("FAILED: expected - " + t.str + ", but got - " + t1.str);
>         } else {
>             System.out.println("PASSED.");
>         }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         private static ObjectStreamClass testOsc = ObjectStreamClass.lookup(Test.class);
>         TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException {
>             ObjectStreamClass osc = super.readClassDescriptor();
>             if(osc.getName().equals("Test")) {
>                 return testOsc;
>             }
>             return osc;
>         }
>     }
> }
> -------------------------
> I've investigated the problem a bit and found that ObjectStreamClass has package-protected method getLoadFields() which is used by ObjectInputStream to get an array of ObjectStreaFields-s to be loaded from the stream in case of default de-serialization. For ObjectStreamClass created by ObjectStreamClass.lookup() method, this method returns an empty array, thus in case of default de-serialization ObjectInputStream does not try to read any field value from the stream - although there are data to be read in the stream.
> I'll provide a patch soon.

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


[jira] Updated: (HARMONY-4638) [classlib][luni] ObjectStreamClass.lookup() incorrectly works

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

Tim Ellison updated HARMONY-4638:
---------------------------------

    Assignee: Tim Ellison

> [classlib][luni] ObjectStreamClass.lookup() incorrectly works
> -------------------------------------------------------------
>
>                 Key: HARMONY-4638
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4638
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>            Assignee: Tim Ellison
>         Attachments: H-4638.patch
>
>
> ObjectStreamClass.lookup() method returns incorrect ObjectStreamClass, which could not be used for replacement in ObjectInputStream.readClassDescriptor(). The test below demonstrates the problem.
> Output on RI: Passed
> Output on Harmony: FAILED: expected - It's a test, but got - null
> --------- Test.java -----------
> import java.io.*;
> public class Test implements Serializable {
>     public String str;
>     public static void main(String[] args) throws Exception {
>         Test t = new Test();
>         t.str = "It's a test";
>         PipedOutputStream pout = new PipedOutputStream();
>         PipedInputStream pin = new PipedInputStream(pout);
>         ObjectOutputStream out = new ObjectOutputStream(pout);
>         TestObjectInputStream in = new TestObjectInputStream(pin);
>         out.writeObject(t);
>         Test t1 = (Test) in.readObject();
>         if (!t.str.equals(t1.str)) {
>             System.out.println("FAILED: expected - " + t.str + ", but got - " + t1.str);
>         } else {
>             System.out.println("PASSED.");
>         }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         private static ObjectStreamClass testOsc = ObjectStreamClass.lookup(Test.class);
>         TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException {
>             ObjectStreamClass osc = super.readClassDescriptor();
>             if(osc.getName().equals("Test")) {
>                 return testOsc;
>             }
>             return osc;
>         }
>     }
> }
> -------------------------
> I've investigated the problem a bit and found that ObjectStreamClass has package-protected method getLoadFields() which is used by ObjectInputStream to get an array of ObjectStreaFields-s to be loaded from the stream in case of default de-serialization. For ObjectStreamClass created by ObjectStreamClass.lookup() method, this method returns an empty array, thus in case of default de-serialization ObjectInputStream does not try to read any field value from the stream - although there are data to be read in the stream.
> I'll provide a patch soon.

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


[jira] Closed: (HARMONY-4638) [classlib][luni] ObjectStreamClass.lookup() incorrectly works

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

Mikhail Markov closed HARMONY-4638.
-----------------------------------


Thanks, Tim! Applied as expected.


> [classlib][luni] ObjectStreamClass.lookup() incorrectly works
> -------------------------------------------------------------
>
>                 Key: HARMONY-4638
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4638
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>            Assignee: Tim Ellison
>         Attachments: H-4638.patch
>
>
> ObjectStreamClass.lookup() method returns incorrect ObjectStreamClass, which could not be used for replacement in ObjectInputStream.readClassDescriptor(). The test below demonstrates the problem.
> Output on RI: Passed
> Output on Harmony: FAILED: expected - It's a test, but got - null
> --------- Test.java -----------
> import java.io.*;
> public class Test implements Serializable {
>     public String str;
>     public static void main(String[] args) throws Exception {
>         Test t = new Test();
>         t.str = "It's a test";
>         PipedOutputStream pout = new PipedOutputStream();
>         PipedInputStream pin = new PipedInputStream(pout);
>         ObjectOutputStream out = new ObjectOutputStream(pout);
>         TestObjectInputStream in = new TestObjectInputStream(pin);
>         out.writeObject(t);
>         Test t1 = (Test) in.readObject();
>         if (!t.str.equals(t1.str)) {
>             System.out.println("FAILED: expected - " + t.str + ", but got - " + t1.str);
>         } else {
>             System.out.println("PASSED.");
>         }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         private static ObjectStreamClass testOsc = ObjectStreamClass.lookup(Test.class);
>         TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException {
>             ObjectStreamClass osc = super.readClassDescriptor();
>             if(osc.getName().equals("Test")) {
>                 return testOsc;
>             }
>             return osc;
>         }
>     }
> }
> -------------------------
> I've investigated the problem a bit and found that ObjectStreamClass has package-protected method getLoadFields() which is used by ObjectInputStream to get an array of ObjectStreaFields-s to be loaded from the stream in case of default de-serialization. For ObjectStreamClass created by ObjectStreamClass.lookup() method, this method returns an empty array, thus in case of default de-serialization ObjectInputStream does not try to read any field value from the stream - although there are data to be read in the stream.
> I'll provide a patch soon.

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


[jira] Updated: (HARMONY-4638) [classlib][luni] ObjectStreamClass.lookup() incorrectly works

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

Mikhail Markov updated HARMONY-4638:
------------------------------------

    Attachment: H-4638.patch

Here is the patch fixing the issue + regression test.

Fix description: 1) loadFields array is filled during createClassDesc() method call in ObjectStreamClass so it become non-null and default reading works ok.
2) The modification in ObjectInputStream related with cyclic reference deserialization: when the same class is read from the stream again, ObjectInputStream found the description of the class in it's table. So if subclass of ObjectInputStream replaces ObjectStreamClass, it should be put to the table instead of the one which was read from the stream. (The regression test for cyclic references is also in the patch).

> [classlib][luni] ObjectStreamClass.lookup() incorrectly works
> -------------------------------------------------------------
>
>                 Key: HARMONY-4638
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4638
>             Project: Harmony
>          Issue Type: Bug
>          Components: App-Oriented Bug Reports, Classlib
>         Environment: Win XP
>            Reporter: Mikhail Markov
>         Attachments: H-4638.patch
>
>
> ObjectStreamClass.lookup() method returns incorrect ObjectStreamClass, which could not be used for replacement in ObjectInputStream.readClassDescriptor(). The test below demonstrates the problem.
> Output on RI: Passed
> Output on Harmony: FAILED: expected - It's a test, but got - null
> --------- Test.java -----------
> import java.io.*;
> public class Test implements Serializable {
>     public String str;
>     public static void main(String[] args) throws Exception {
>         Test t = new Test();
>         t.str = "It's a test";
>         PipedOutputStream pout = new PipedOutputStream();
>         PipedInputStream pin = new PipedInputStream(pout);
>         ObjectOutputStream out = new ObjectOutputStream(pout);
>         TestObjectInputStream in = new TestObjectInputStream(pin);
>         out.writeObject(t);
>         Test t1 = (Test) in.readObject();
>         if (!t.str.equals(t1.str)) {
>             System.out.println("FAILED: expected - " + t.str + ", but got - " + t1.str);
>         } else {
>             System.out.println("PASSED.");
>         }
>     }
>     static class TestObjectInputStream extends ObjectInputStream {
>         private static ObjectStreamClass testOsc = ObjectStreamClass.lookup(Test.class);
>         TestObjectInputStream(InputStream in) throws IOException {
>             super(in);
>         }
>         protected ObjectStreamClass readClassDescriptor() throws ClassNotFoundException, IOException {
>             ObjectStreamClass osc = super.readClassDescriptor();
>             if(osc.getName().equals("Test")) {
>                 return testOsc;
>             }
>             return osc;
>         }
>     }
> }
> -------------------------
> I've investigated the problem a bit and found that ObjectStreamClass has package-protected method getLoadFields() which is used by ObjectInputStream to get an array of ObjectStreaFields-s to be loaded from the stream in case of default de-serialization. For ObjectStreamClass created by ObjectStreamClass.lookup() method, this method returns an empty array, thus in case of default de-serialization ObjectInputStream does not try to read any field value from the stream - although there are data to be read in the stream.
> I'll provide a patch soon.

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