mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 09:21:03 +00:00
ICU-13177 Fixing serialization test failures in ICU4J.
X-SVN-Rev: 40478
This commit is contained in:
parent
104b56d22e
commit
b7bedcbab0
6 changed files with 78 additions and 9 deletions
|
@ -537,6 +537,10 @@ public class DecimalFormatProperties implements Cloneable, Serializable {
|
|||
|
||||
/** Custom serialization: re-create object from serialized properties. */
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
readObjectImpl(ois);
|
||||
}
|
||||
|
||||
/* package-private */ void readObjectImpl(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
ois.defaultReadObject();
|
||||
|
||||
// Initialize to empty
|
||||
|
@ -1301,6 +1305,10 @@ public class DecimalFormatProperties implements Cloneable, Serializable {
|
|||
* the future in any order. Only save fields that differ from their default value.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
writeObjectImpl(oos);
|
||||
}
|
||||
|
||||
/* package-private */ void writeObjectImpl(ObjectOutputStream oos) throws IOException {
|
||||
oos.defaultWriteObject();
|
||||
|
||||
// Extra int for possible future use
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// © 2017 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html#License
|
||||
package com.ibm.icu.impl.number;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ICU 59 called the class DecimalFormatProperties as just Properties. We need to keep a thin implementation for the
|
||||
* purposes of serialization.
|
||||
*/
|
||||
public class Properties implements Serializable {
|
||||
|
||||
/** Same as DecimalFormatProperties. */
|
||||
private static final long serialVersionUID = 4095518955889349243L;
|
||||
|
||||
private transient DecimalFormatProperties instance;
|
||||
|
||||
public DecimalFormatProperties getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
if (instance == null) {
|
||||
instance = new DecimalFormatProperties();
|
||||
}
|
||||
instance.readObjectImpl(ois);
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
if (instance == null) {
|
||||
instance = new DecimalFormatProperties();
|
||||
}
|
||||
instance.writeObjectImpl(oos);
|
||||
}
|
||||
}
|
|
@ -217,15 +217,13 @@ final class NumberPropertyMapper {
|
|||
// This whole section feels like a hack, but it is needed for regression tests.
|
||||
// The mapping from property bag to scientific notation is nontrivial due to LDML rules.
|
||||
// The maximum of 8 digits has unknown origins and is not in the spec.
|
||||
if (maxInt > 8) {
|
||||
if (minInt > 8) {
|
||||
minInt = 8;
|
||||
maxInt = 8;
|
||||
if (minInt > maxInt) {
|
||||
minInt = maxInt;
|
||||
}
|
||||
macros.integerWidth = IntegerWidth.zeroFillTo(minInt).truncateAt(maxInt);
|
||||
}
|
||||
int engineering = (maxInt != -1) ? maxInt : properties.getMaximumIntegerDigits();
|
||||
engineering = (engineering < 0) ? 0 : (engineering > 8) ? minInt : engineering;
|
||||
int engineering = maxInt > 8 ? minInt : maxInt < minInt ? -1 : maxInt;
|
||||
engineering = (engineering < 0) ? 0 : engineering;
|
||||
// Bug #13289: if maxInt > minInt > 1, then minInt should be 1.
|
||||
// Clear out IntegerWidth to prevent padding extra zeros.
|
||||
if (maxInt > minInt && minInt > 1) {
|
||||
|
|
|
@ -527,7 +527,14 @@ public class DecimalFormat extends NumberFormat {
|
|||
// Extra int for possible future use:
|
||||
ois.readInt();
|
||||
// 1) Property Bag
|
||||
properties = (DecimalFormatProperties) ois.readObject();
|
||||
Object serializedProperties = ois.readObject();
|
||||
if (serializedProperties instanceof DecimalFormatProperties) {
|
||||
// ICU 60+
|
||||
properties = (DecimalFormatProperties) serializedProperties;
|
||||
} else {
|
||||
// ICU 59
|
||||
properties = ((com.ibm.icu.impl.number.Properties) serializedProperties).getInstance();
|
||||
}
|
||||
// 2) DecimalFormatSymbols
|
||||
symbols = (DecimalFormatSymbols) ois.readObject();
|
||||
// Re-build transient fields
|
||||
|
|
|
@ -30,10 +30,10 @@ import org.junit.Test;
|
|||
|
||||
import com.ibm.icu.dev.test.serializable.SerializableTestUtility;
|
||||
import com.ibm.icu.impl.number.DecimalFormatProperties;
|
||||
import com.ibm.icu.impl.number.Padder.PadPosition;
|
||||
import com.ibm.icu.impl.number.Parse.GroupingMode;
|
||||
import com.ibm.icu.impl.number.Parse.ParseMode;
|
||||
import com.ibm.icu.impl.number.PatternStringParser;
|
||||
import com.ibm.icu.impl.number.Padder.PadPosition;
|
||||
import com.ibm.icu.text.CompactDecimalFormat.CompactStyle;
|
||||
import com.ibm.icu.text.CurrencyPluralInfo;
|
||||
import com.ibm.icu.text.MeasureFormat.FormatWidth;
|
||||
|
@ -347,4 +347,20 @@ public class PropertiesTest {
|
|||
return a.equals(b);
|
||||
}
|
||||
}
|
||||
|
||||
/** Handler for the ICU 59 class named "Properties" before it was renamed to "DecimalFormatProperties". */
|
||||
public static class ICU59PropertiesHandler implements SerializableTestUtility.Handler {
|
||||
|
||||
@Override
|
||||
public Object[] getTestObjects() {
|
||||
return new Object[] {
|
||||
new com.ibm.icu.impl.number.Properties()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSameBehavior(Object a, Object b) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -829,7 +829,9 @@ public class SerializableTestUtility {
|
|||
map.put("com.ibm.icu.util.TimeUnit", new MeasureUnitTest.MeasureUnitHandler());
|
||||
map.put("com.ibm.icu.util.NoUnit", new MeasureUnitTest.MeasureUnitHandler());
|
||||
map.put("com.ibm.icu.text.MeasureFormat", new MeasureUnitTest.MeasureFormatHandler());
|
||||
map.put("com.ibm.icu.impl.number.Properties", new PropertiesTest.PropertiesHandler());
|
||||
map.put("com.ibm.icu.impl.number.Properties", new PropertiesTest.ICU59PropertiesHandler());
|
||||
map.put("com.ibm.icu.impl.number.DecimalFormatProperties", new PropertiesTest.PropertiesHandler());
|
||||
map.put("com.ibm.icu.impl.number.CustomSymbolCurrency", new CurrencyHandler());
|
||||
|
||||
map.put("com.ibm.icu.util.ICUException", new ICUExceptionHandler());
|
||||
map.put("com.ibm.icu.util.ICUUncheckedIOException", new ICUUncheckedIOExceptionHandler());
|
||||
|
|
Loading…
Add table
Reference in a new issue