-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: mgC56079 Date: 10/13/97
The java.math.BigDecimal class serialized on jdk1.1.4 platform fails to be
deserialized on jdk1.2 platform due to the incompatibility of the class on
jdk1.1.4 and jdk1.2 platforms.
Here is the test demonstraiting the bug:
----------BigDecimalTest.java----------------
import java.io.*;
import java.math.BigDecimal;
public class BigDecimalTest {
public static void main(String args[]) {
BigDecimal bigDecimal;
String filepath = "BigDecimal.ser";
if (args[0].equals("write")) {
bigDecimal = new BigDecimal("0");
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(new FileOutputStream(filepath));
stream.writeObject(bigDecimal);
stream.close();
} catch(IOException e) {
System.out.println("Couldn't write to " + filepath + " : " + e);
System.exit(1);
}
System.out.println("BigDecimal written successfully");
} else if (args[0].equals("read")) {
ObjectInputStream stream = null;
try {
stream = new ObjectInputStream(new FileInputStream(filepath));
bigDecimal = (BigDecimal)stream.readObject();
} catch(InvalidClassException e) {
System.out.println("Failed:" + e);
System.exit(1);
} catch(Exception e) {
System.out.println(
"Failed: couldn't read from" + filepath + " : " + e
);
System.exit(1);
}
System.out.println("Passed");
}
System.exit(0);
}
}
----------The test output on jdk1.1.4-----------
#>java BigDecimalTest write
BigDecimal written successfully
#>java BigDecimalTest read
Passed
----------The test output on jdk1.2-------------
#>java BigDecimalTest read
Failed:java.io.InvalidClassException: java.math.BigDecimal; Local class not compatible
======================================================================
- duplicates
-
JDK-4076531 java.math.BigDecimal: Change in SerialVersionUID In Class java.math.BigDecimal
- Closed