8232860: Error formatting integer values with MessageFormat.format() using HOST provider

Reviewed-by: rriggs
This commit is contained in:
Naoto Sato 2019-11-12 14:05:18 -08:00
parent de54eb1513
commit 9803a8dcb2
6 changed files with 69 additions and 5 deletions

View file

@ -429,8 +429,9 @@ public class HostLocaleProviderAdapterImpl {
@Override
public NumberFormat getIntegerInstance(Locale locale) {
return new DecimalFormat(getNumberPattern(NF_INTEGER, locale),
DecimalFormat format = new DecimalFormat(getNumberPattern(NF_INTEGER, locale),
DecimalFormatSymbols.getInstance(locale));
return HostLocaleProviderAdapter.makeIntegerFormatter(format);
}
@Override

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@ package sun.util.locale.provider;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.util.spi.LocaleServiceProvider;
/**
@ -60,4 +61,19 @@ public class HostLocaleProviderAdapter extends AuxLocaleProviderAdapter {
}
return null;
}
/**
* Utility to make the decimal format specific to integer, called
* by the platform dependent adapter implementations.
*
* @param df A DecimalFormat object
* @return The same DecimalFormat object in the argument, modified
* to allow integer formatting/parsing only.
*/
static DecimalFormat makeIntegerFormatter(DecimalFormat df) {
df.setMaximumFractionDigits(0);
df.setDecimalSeparatorAlwaysShown(false);
df.setParseIntegerOnly(true);
return df;
}
}

View file

@ -258,8 +258,9 @@ public class HostLocaleProviderAdapterImpl {
@Override
public NumberFormat getIntegerInstance(Locale locale) {
AtomicReferenceArray<String> patterns = getNumberPatterns(locale);
return new DecimalFormat(patterns.get(NF_INTEGER),
DecimalFormat format = new DecimalFormat(patterns.get(NF_INTEGER),
DecimalFormatSymbols.getInstance(locale));
return HostLocaleProviderAdapter.makeIntegerFormatter(format);
}
@Override

View file

@ -910,7 +910,7 @@ void getNumberPart(const jchar * langtag, const jint numberStyle, WCHAR * number
if (digits > 0) {
int i;
for(i = digits; i > 0; i--) {
fractionPattern[i] = L'0';
fractionPattern[i] = L'#';
}
fractionPattern[0] = L'.';
fractionPattern[digits+1] = L'\0';