You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Alexei Zakharov (JIRA)" <ji...@apache.org> on 2007/03/01 14:29:51 UTC
[jira] Closed: (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 ]
Alexei Zakharov closed HARMONY-3158.
------------------------------------
Was verified by Mikhail. Closed.
> [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
> Assigned To: Alexei Zakharov
> 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.