-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: avC70361 Date: 05/18/98
Th java.lanag.NumberFormat instances obtained with method
getCurrencyInstance(Locale locale) for some locales are incorrectly deserialized
in jdk1.2beta4 when have been serialized in jdk1.1.6.
Here is the test demonstrating the bug.
-----------NumberFormatTest.java----------
import java.util.Locale;
public class NumberFormatTest {
public static void main(String args[]) {
Locale[] locales = {
Locale.CANADA,
Locale.CANADA_FRENCH,
Locale.CHINA,
Locale.CHINESE,
Locale.ENGLISH,
Locale.FRANCE,
Locale.FRENCH,
Locale.GERMAN,
Locale.GERMANY,
Locale.ITALIAN,
Locale.ITALY,
Locale.JAPAN,
Locale.JAPANESE,
Locale.KOREA,
Locale.KOREAN,
Locale.PRC,
Locale.SIMPLIFIED_CHINESE,
Locale.TAIWAN,
Locale.TRADITIONAL_CHINESE,
Locale.UK,
Locale.US
};
if (args[0].equals("write")) {
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(new FileOutputStream(args[1]));
for(int i = 0; i < locales.length; i++) {
stream.writeObject(NumberFormat.getCurrencyInstance(locales[i]));
}
stream.close();
} catch(IOException e) {
System.out.println("Couldn't write to " + args[1] + " : " + e);
System.exit(1);
}
System.out.println(args[1] + " written successfully");
} else if (args[0].equals("read")) {
ObjectInputStream stream = null;
try {
stream = new ObjectInputStream(new FileInputStream(args[1]));
} catch(Exception e) {
System.out.println(
"Failed: couldn't read from" + args[1] + " : " + e
);
System.exit(1);
}
int errors = 0;
for(int i = 0; i < locales.length; i++) {
try {
NumberFormat format = (NumberFormat)stream.readObject();
if (!format.equals(NumberFormat.getCurrencyInstance(locales[i]))) {
System.out.println("Failed for locale : " + locales[i] + " : format returned is not equal to expected");
errors++;
}
} catch(Exception e) {
System.out.println("Failed for locale : " + locales[i] + " : " + e);
errors++;
}
}
if (errors == 0) {
System.out.println("Passed");
}
}
System.exit(0);
}
}
-----------Test output-----------
On jdk1.1.6:
<avv@stardust(pts/13).530> java -fullversion
java full version "JDK1.1.6N"
<avv@stardust(pts/13).531> java NumberFormatTest write file.ser
file.ser written successfully
<avv@stardust(pts/13).532> java NumberFormatTest read file.ser
Passed
On jdk1.2beta4:
<avv@stardust(pts/2).673> java -fullversion
java full version "JDK-1.2beta4-F"
<avv@stardust(pts/2).674> java NumberFormatTest read file.ser
Failed for locale : zh : format returned is not equal to expected
Failed for locale : en : format returned is not equal to expected
Failed for locale : fr : format returned is not equal to expected
Failed for locale : de : format returned is not equal to expected
Failed for locale : it : format returned is not equal to expected
Failed for locale : ja : format returned is not equal to expected
Failed for locale : ko : format returned is not equal to expected
======================================================================