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/02/12 22:12:06 UTC

[jira] Updated: (HARMONY-3158) [classlib][luni]ObjectOutputStream.replaceObject fails when serializable object is Class or interface

     [ https://issues.apache.org/jira/browse/HARMONY-3158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mikhail Markov updated HARMONY-3158:
------------------------------------

    Attachment: H-3158.patch

Fix description: ObjectOutputStream incorrectly serialized Class and ObjectStreamClass objects (i.e. uses ordinal writeNewObject() method instead of special ones) when stream-based replacement is enabled. This led to unpredictable consequences while serializing and, sometimes, de-serializing classes (as the written stream was corrupted).
So, the fix added the calls to the special methods for Class and ObjectStreamClass in this case.

The regression test tests the cases described in the initial description for this JIRA + the case for ObjectStreamClass.

Could someone from the committers try this patch? Thanks!

> [classlib][luni]ObjectOutputStream.replaceObject fails when serializable object is Class or interface
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3158
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3158
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Igor V. Stolyarov
>         Attachments: H-3158.patch
>
>
> ObjectOutputStream.replaceObject fails when serializable object is Class or interface
> Test:
> import java.net.*;
> import java.io.*;
> import java.util.*;
> public class Test{
>         
>     private static class ObjectOutputStreamWithReplace extends
>             ObjectOutputStream {
>         public ObjectOutputStreamWithReplace(OutputStream out)
>                 throws IOException {
>             super(out);
>             enableReplaceObject(true);
>         }
>         protected Object replaceObject(Object obj) throws IOException {
>             if(obj instanceof Integer) obj = new Long(10);
>             return obj;
>         }
>     }
>     public static void main(String argv[]){
>         try {
>             HashMap hm = new HashMap();
>             hm.put("Long", new Integer(10));
>             hm.put("Integer class", Integer.class);
>             ByteArrayOutputStream baos = new ByteArrayOutputStream();
>             ObjectOutputStream oos = new ObjectOutputStream(baos);
>             oos.writeObject(hm);
>             oos.flush();
>             ObjectInputStream ois = new ObjectInputStream(
>                    new ByteArrayInputStream(baos.toByteArray()));
>             
>             HashMap hm1 = (HashMap)ois.readObject();
>             oos.close();
>             ois.close();
>             
>             Object obj = hm1.get("Long");
>             if(obj instanceof Integer) System.out.println("Test part 1 - passed");
>             else System.out.println("Test part 1 - failed"); 
>             obj = hm1.get("Integer class");
>             if(obj == Integer.class) System.out.println("Test part 2 - passed");
>             else System.out.println("Test part 2 - failed");
>             baos = new ByteArrayOutputStream();
>             ObjectOutputStreamWithReplace ooswr = new ObjectOutputStreamWithReplace(
>                                 baos);
>             ooswr.writeObject(hm);
>             ooswr.flush();
>             ois = new ObjectInputStream(
>                    new ByteArrayInputStream(baos.toByteArray()));
>             
>             hm1 = (HashMap)ois.readObject();
>             ooswr.close();
>             ois.close();
>             
>             obj = hm1.get("Long");
>             if(obj instanceof Long) System.out.println("Test part 3 - passed");
>             else System.out.println("Test part 3 - failed"); 
>             obj = hm1.get("Integer class");
>             if(obj == Integer.class) System.out.println("Test part 4 - passed");
>             else System.out.println("Test part 4 - failed");
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
> ------------------------------------------------
> Output:
> JRockit jdk:
> java version "1.5.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
> BEA WebLogic JRockit(R) (build dra-38972-20041208-2001-win-ia32, R25.0.0-75, GC:
>  System optimized over throughput (initial strategy singleparpar))
> Test part 1 - passed
> Test part 2 - passed
> Test part 3 - passed
> Test part 4 - passed
> -------------------------------------------------------------
> Harmony:
> Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundatio
> n or its licensors, as applicable.
> java version "1.5.0"
> pre-alpha : not complete or compatible
> svn = r504458, (Feb  7 2007), Windows/ia32/msvc 1310, release build
> http://incubator.apache.org/harmony
> Test part 1 - passed
> Test part 2 - passed
> Test part 3 - passed
> Test part 4 - failed

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