Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 94047 invoked from network); 20 Nov 2006 10:15:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Nov 2006 10:15:54 -0000 Received: (qmail 71702 invoked by uid 500); 20 Nov 2006 10:16:04 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 71678 invoked by uid 500); 20 Nov 2006 10:16:04 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 71657 invoked by uid 99); 20 Nov 2006 10:16:04 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Nov 2006 02:16:04 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Nov 2006 02:15:53 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id DAEFC1A9846; Mon, 20 Nov 2006 02:15:19 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r477132 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectInputStream.java test/java/tests/api/java/io/ObjectInputStreamTest.java Date: Mon, 20 Nov 2006 10:15:19 -0000 To: commits@harmony.apache.org From: liangyx@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061120101519.DAEFC1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: liangyx Date: Mon Nov 20 02:15:18 2006 New Revision: 477132 URL: http://svn.apache.org/viewvc?view=rev&rev=477132 Log: Apply patch for HARMONY-2192 ([classlib][ObjectStreamInputStream]Fails to deserialze an object created by cglib) Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?view=diff&rev=477132&r1=477131&r2=477132 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java Mon Nov 20 02:15:18 2006 @@ -107,6 +107,19 @@ // cache for readResolve methods private IdentityHashMap, Object> readResolveCache; + + private static final Hashtable PRIMITIVE_CLASSES = new Hashtable(); + + static { + PRIMITIVE_CLASSES.put("byte", byte.class); + PRIMITIVE_CLASSES.put("short", short.class); + PRIMITIVE_CLASSES.put("int", int.class); + PRIMITIVE_CLASSES.put("long", long.class); + PRIMITIVE_CLASSES.put("boolean", boolean.class); + PRIMITIVE_CLASSES.put("char", char.class); + PRIMITIVE_CLASSES.put("float", float.class); + PRIMITIVE_CLASSES.put("double", double.class); + } // Internal type used to keep track of validators & corresponding priority class InputValidationDesc { @@ -2350,11 +2363,18 @@ * If the corresponding class cannot be found. */ protected Class resolveClass(ObjectStreamClass osClass) - throws IOException, ClassNotFoundException { - // Use the first non-null ClassLoader on the stack. If null, use the - // system class loader - return Class.forName(osClass.getName(), true, callerClassLoader); - } + throws IOException, ClassNotFoundException { + String className = osClass.getName(); + //if it is primitive class, for example, long.class + Class cls = PRIMITIVE_CLASSES.get(className); + if (null == cls) { + //not primitive class + //Use the first non-null ClassLoader on the stack. If null, use the + // system class loader + return cls = Class.forName(className, true, callerClassLoader); + } + return cls; + } /** * If enableResolveObject() was activated, computes the Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?view=diff&rev=477132&r1=477131&r2=477132 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java Mon Nov 20 02:15:18 2006 @@ -19,6 +19,9 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.NotActiveException; @@ -28,6 +31,7 @@ import java.io.SerializablePermission; import java.io.StreamCorruptedException; import java.security.Permission; +import java.util.Arrays; import java.util.Hashtable; import java.util.Vector; @@ -634,6 +638,23 @@ fail("NullPointerException expected"); } catch (NullPointerException e) {} } + + // Regression Test for JIRA 2192 + public void test_readObject_withPrimitiveClass() throws Exception { + File file = new File("test.ser"); + file.deleteOnExit(); + Test test = new Test(); + ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream( + file)); + out.writeObject(test); + out.close(); + + ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); + Test another = (Test) in.readObject(); + in.close(); + assertEquals(test, another); + } + /** * Sets up the fixture, for example, open a network connection. This method @@ -643,4 +664,19 @@ super.setUp(); oos = new ObjectOutputStream(bao = new ByteArrayOutputStream()); } +} + + +class Test implements Serializable { + private static final long serialVersionUID = 1L; + + Class classes[] = new Class[] { byte.class, short.class, int.class, + long.class, boolean.class, char.class, float.class, double.class }; + + public boolean equals(Object o) { + if (!(o instanceof Test)) { + return false; + } + return Arrays.equals(classes, ((Test) o).classes); + } }