harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r465141 - in /incubator/harmony/enhanced/classlib/trunk/modules/math/src: main/java/java/math/BigDecimal.java test/java/tests/api/java/math/BigDecimalTest.java
Date Wed, 18 Oct 2006 04:42:14 GMT
Author: mloenko
Date: Tue Oct 17 21:42:13 2006
New Revision: 465141

URL: http://svn.apache.org/viewvc?view=rev&rev=465141
Log:
fixed BigDecimal serialization, applied patch from HARMONY-1896
 [classlib][math] Serialization of BigDecimal works incorrtly

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java?view=diff&rev=465141&r1=465140&r2=465141
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
Tue Oct 17 21:42:13 2006
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.io.StreamCorruptedException;
 
@@ -1932,16 +1933,30 @@
     }
 
     /** @ar.org.fitc.spec_ref */
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
+    private void readObject(ObjectInputStream in) throws IOException,
+            ClassNotFoundException {
         in.defaultReadObject();
-        if (getUnscaledValue() == null) {
-            // math.0B=null unscaled value
-            throw new StreamCorruptedException(Messages.getString("math.0B")); //$NON-NLS-1$
+
+        // see comment to getUnscaledValue()
+//        if (getUnscaledValue() == null) {
+//            // math.0B=null unscaled value
+//            throw new StreamCorruptedException(Messages.getString("math.0B")); //$NON-NLS-1$
+//        }
+
+        this.bitLength = intVal.bitLength();
+        if (this.bitLength < 64) {
+            this.smallValue = intVal.longValue();
         }
-        bitLength = getUnscaledValue().bitLength();
     }
 
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        getUnscaledValue();
+        out.defaultWriteObject();
+    }
+
+
     private BigInteger getUnscaledValue() {
+        // This method is not supposed to return null. Otherwise uncomment 'if' in readObject

         if(intVal == null) {
             intVal = BigInteger.valueOf(smallValue);
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java?view=diff&rev=465141&r1=465140&r2=465141
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
Tue Oct 17 21:42:13 2006
@@ -17,6 +17,10 @@
 
 package tests.api.java.math;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 
@@ -868,4 +872,22 @@
 				valueOfJI.toString().equals("0.000"));
 
 	}
+
+	public void test_BigDecimal_serialization() throws Exception {
+        // Regression for HARMONY-1896
+        char[] in = { '1', '5', '6', '7', '8', '7', '.', '0', '0' };
+        BigDecimal bd = new BigDecimal(in, 0, 9);
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(bos);
+        oos.writeObject(bd);
+
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+        ObjectInputStream ois = new ObjectInputStream(bis);
+        BigDecimal nbd = (BigDecimal) ois.readObject();
+
+        assertEquals(bd.intValue(), nbd.intValue());
+        assertEquals(bd.doubleValue(), nbd.doubleValue(), 0.0);
+        assertEquals(bd.toString(), nbd.toString());
+    }
 }



Mime
View raw message