- 
    Type:
Bug
 - 
    Resolution: Duplicate
 - 
    Priority:
  P3                     
     - 
    None
 - 
    Affects Version/s: 1.3.0
 - 
    Component/s: other-libs
 
- 
        sparc
 - 
        solaris_7
 
Name: avC70361 Date: 05/13/99
The java.math.BigInteger objects serialization is wrong under jdk1.3. In a case when BigInteger object
represents 0 has been serialized, it can't be deserialized then because the "java.io.StreamCorruptedException:
BigInteger: signum-magnitude mismatch" is thrown during deserialization. That is because BigInteger.
writeObject() method use toByteArray() method to intialize serializable field 'magnitude', but this method
returns not zero-length array for BigInteger representing 0. The 'magnitude' field should be zero-length array
for zero BigInteger in order to be correcty read by readObject() of jdk 1.3 and earlier versions.
Here is a test demonstrating the bug.
----------------BigIntegerTest.java--------------------
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
public class BigIntegerTest {
public static void main(String[] args) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(new BigInteger("0"));
oos.flush();
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(baos.toByteArray())
);
ois.readObject();
System.out.println("Passed.");
} catch(Exception e) {
System.out.println("Failed. Unexpected exception : " + e);
}
}
}
----------------The test output---------------------
> java BigIntegerTest
Failed. Unexpected exception : java.io.StreamCorruptedException: BigInteger: signum-magnitude mismatch
======================================================================
- duplicates
 - 
                    
JDK-4233720 Kestrel build "B" fails ../../serialization/manual.html#BigDecimal,#BigInteger
-         
     - Closed
 
 -