Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 6816 invoked from network); 19 Oct 2006 15:24:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Oct 2006 15:24:34 -0000 Received: (qmail 50343 invoked by uid 500); 19 Oct 2006 15:24:29 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 50299 invoked by uid 500); 19 Oct 2006 15:24:29 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 50288 invoked by uid 99); 19 Oct 2006 15:24:29 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Oct 2006 08:24:29 -0700 X-ASF-Spam-Status: No, hits=2.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mikhail.a.markov@gmail.com designates 72.14.204.233 as permitted sender) Received: from [72.14.204.233] (HELO qb-out-0506.google.com) (72.14.204.233) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Oct 2006 08:24:26 -0700 Received: by qb-out-0506.google.com with SMTP id a33so18071qbd for ; Thu, 19 Oct 2006 08:24:05 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=U1aJ8fsgEGXH0KMPTjufLIIAN6v7djW4QJleLGtSRqKk+ZLC838tiuDunUTnH934fEsqiuiV2pE7jF7hv7TluDr1cPMW3FToP1dQv1GXQx5PHZA0pVrk0SJTJVvCwTNp/KhTWN6/IuDcvKX4h5/UPj5lrQOIWfC9S7XrBF6ruWI= Received: by 10.66.220.17 with SMTP id s17mr108802ugg; Thu, 19 Oct 2006 08:24:04 -0700 (PDT) Received: by 10.66.240.20 with HTTP; Thu, 19 Oct 2006 08:24:04 -0700 (PDT) Message-ID: <51abf0750610190824n7ec8395el59290c035b4f305b@mail.gmail.com> Date: Thu, 19 Oct 2006 19:24:04 +0400 From: "Mikhail Markov" To: harmony-dev@incubator.apache.org Subject: [classlib][serialization] Conditional object replacement in ObjectInputStream - bug in RI? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_237609_13392146.1161271444910" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_237609_13392146.1161271444910 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi! I've recently filed 2 JIRAs (HARMONY-1920 and HARMONY 1921) related to the object replacement in ObjectInputStream by means of resolveObject() method and during experimenting with the tests, created the test which replaces the object according to some rule (see the code at the bottom of the message). Unexpectedly it fails on RI with the output: TestObjectInputStream.resolveClass() is called. 1-st read passed. 2-nd read failed with exception: java.lang.ClassCastException: b.TestClass This output indicates that RI performs caching for object replacements and second read just did not call resolveClass() method from TestObjectInputStream. I did not find any info about this case in serialization specification and not quite sure if this behaviour is correct. Is this a bug in RI? If not then this case should be also taken into account while fixing HARMONY-1921 JIRA. ------------------------- 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; a.TestClass to2 = new a.TestClass(); to2.i = 777; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(to1); oos.writeObject(to2); oos.flush(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new TestObjectInputStream(bais); try { b.TestClass to3 = (b.TestClass) ois.readObject(); if (to3.i != to1.i) { System.out.println("1-st read failed. Expected: " + to1.i + ", got: " + to3.i); } else { System.out.println("1-st read passed."); } } catch (Exception ex) { System.out.println("1-st read failed with exception: " + ex); } try { a.TestClass to4 = (a.TestClass) ois.readObject(); if (to4.i != to2.i) { System.out.println("2-nd read failed. Expected: " + to2.i + ", got: " + to4.i); } else { System.out.println("2-nd read passed."); } } catch (Exception ex) { System.out.println("2-nd read failed with exception: " + ex); } } static class TestObjectInputStream extends ObjectInputStream { private boolean replaced = false; public TestObjectInputStream(InputStream in) throws IOException { super(in); } protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { if (desc.getName().equals("a.TestClass")) { System.out.println("TestObjectInputStream.resolveClass() is called."); if (!replaced) { replaced = true; return b.TestClass.class; } else { return a.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; } ----------------------------------------------------------------- Mikhail Markov Intell Middleware Products Division ------=_Part_237609_13392146.1161271444910--