mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8248695: HostLocaleProviderAdapterImpl provides invalid date-only
Reviewed-by: joehw
This commit is contained in:
parent
10e6a6a19a
commit
f8f35d30af
4 changed files with 101 additions and 57 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2020, 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
|
||||
|
@ -388,6 +388,10 @@ public class HostLocaleProviderAdapterImpl {
|
|||
int value, int style, Locale locale) {
|
||||
String[] names = getCalendarDisplayStrings(removeExtensions(locale).toLanguageTag(),
|
||||
getCalendarIDFromLDMLType(calendarType), field, style);
|
||||
if (field == Calendar.DAY_OF_WEEK) {
|
||||
// Align value to array index
|
||||
value--;
|
||||
}
|
||||
if (names != null && value >= 0 && value < names.length) {
|
||||
return names[value];
|
||||
} else {
|
||||
|
@ -405,7 +409,9 @@ public class HostLocaleProviderAdapterImpl {
|
|||
map = new HashMap<>();
|
||||
for (int value = 0; value < names.length; value++) {
|
||||
if (names[value] != null) {
|
||||
map.put(names[value], value);
|
||||
map.put(names[value],
|
||||
// Align array index to field value
|
||||
field == Calendar.DAY_OF_WEEK ? value + 1 : value);
|
||||
}
|
||||
}
|
||||
map = map.isEmpty() ? null : map;
|
||||
|
@ -549,12 +555,10 @@ public class HostLocaleProviderAdapterImpl {
|
|||
@Override
|
||||
public String getJavaTimeDateTimePattern(int timeStyle, int dateStyle, String calType, Locale locale) {
|
||||
AtomicReferenceArray<String> patterns = getDateTimePatterns(locale);
|
||||
String pattern = new StringBuilder(patterns.get(dateStyle / 2))
|
||||
.append(" ")
|
||||
.append(patterns.get(timeStyle / 2 + 2))
|
||||
.toString();
|
||||
return toJavaTimeDateTimePattern(calType, pattern);
|
||||
|
||||
String datePattern = dateStyle != - 1 ? patterns.get(dateStyle / 2) : "";
|
||||
String timePattern = timeStyle != - 1 ? patterns.get(timeStyle / 2 + 2) : "";
|
||||
String delim = dateStyle != -1 && timeStyle != - 1 ? " " : "";
|
||||
return toJavaTimeDateTimePattern(calType, datePattern + delim + timePattern);
|
||||
}
|
||||
|
||||
private AtomicReferenceArray<String> getDateTimePatterns(Locale locale) {
|
||||
|
@ -699,7 +703,7 @@ public class HostLocaleProviderAdapterImpl {
|
|||
private static String convertDateTimePattern(String winPattern) {
|
||||
String ret = winPattern.replaceAll("dddd", "EEEE");
|
||||
ret = ret.replaceAll("ddd", "EEE");
|
||||
ret = ret.replaceAll("tt", "aa");
|
||||
ret = ret.replaceAll("tt", "a");
|
||||
ret = ret.replaceAll("g", "GG");
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2020, 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
|
||||
|
@ -34,6 +34,8 @@
|
|||
// java.util.Calendar constants
|
||||
#define CALENDAR_FIELD_ERA 0 // Calendar.ERA
|
||||
#define CALENDAR_FIELD_MONTH 2 // Calendar.MONTH
|
||||
#define CALENDAR_FIELD_DAY_OF_WEEK 7 // Calendar.DAY_OF_WEEK
|
||||
#define CALENDAR_FIELD_AM_PM 9 // Calendar.AM_PM
|
||||
#define CALENDAR_STYLE_SHORT_MASK 0x00000001 // Calendar.SHORT
|
||||
#define CALENDAR_STYLE_STANDALONE_MASK 0x00008000 // Calendar.STANDALONE
|
||||
|
||||
|
@ -50,8 +52,7 @@ BOOL initialized = FALSE;
|
|||
int getLocaleInfoWrapper(const jchar *langtag, LCTYPE type, LPWSTR data, int buflen);
|
||||
int getCalendarInfoWrapper(const jchar *langtag, CALID id, LPCWSTR reserved, CALTYPE type, LPWSTR data, int buflen, LPDWORD val);
|
||||
jint getCalendarID(const jchar *langtag);
|
||||
void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jint calid, jobjectArray jarray,
|
||||
CALTYPE* pCalTypes, int offset, int length, int style);
|
||||
void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jint calid, jobjectArray jarray, DWORD* pTypes, int offset, int length, int style, BOOL bCal);
|
||||
WCHAR * getNumberPattern(const jchar * langtag, const jint numberStyle);
|
||||
void getNumberPart(const jchar * langtag, const jint numberStyle, WCHAR * number);
|
||||
void getFixPart(const jchar * langtag, const jint numberStyle, BOOL positive, BOOL prefix, WCHAR * ret);
|
||||
|
@ -116,6 +117,15 @@ CALTYPE sWDaysType[] = {
|
|||
CAL_SABBREVDAYNAME6,
|
||||
};
|
||||
|
||||
#define DOWTYPES (sizeof(wDaysType) / sizeof(CALTYPE))
|
||||
|
||||
LCTYPE ampmType [] = {
|
||||
LOCALE_SAM,
|
||||
LOCALE_SPM,
|
||||
};
|
||||
|
||||
#define AMPMTYPES (sizeof(ampmType) / sizeof(LCTYPE))
|
||||
|
||||
WCHAR * fixes[2][2][3][16] =
|
||||
{
|
||||
{ //prefix
|
||||
|
@ -278,35 +288,8 @@ JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterIm
|
|||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
|
||||
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
|
||||
WCHAR buf[BUFLEN];
|
||||
const jchar *langtag;
|
||||
jstring tmp_string;
|
||||
|
||||
// AM
|
||||
int got;
|
||||
langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
|
||||
CHECK_NULL_RETURN(langtag, NULL);
|
||||
got = getLocaleInfoWrapper(langtag, LOCALE_S1159, buf, BUFLEN);
|
||||
if (got) {
|
||||
tmp_string = (*env)->NewString(env, buf, (jsize)wcslen(buf));
|
||||
if (tmp_string != NULL) {
|
||||
(*env)->SetObjectArrayElement(env, ampms, 0, tmp_string);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(*env)->ExceptionCheck(env)){
|
||||
// PM
|
||||
got = getLocaleInfoWrapper(langtag, LOCALE_S2359, buf, BUFLEN);
|
||||
if (got) {
|
||||
tmp_string = (*env)->NewString(env, buf, (jsize)wcslen(buf));
|
||||
if (tmp_string != NULL) {
|
||||
(*env)->SetObjectArrayElement(env, ampms, 1, tmp_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(*env)->ReleaseStringChars(env, jlangtag, langtag);
|
||||
|
||||
replaceCalendarArrayElems(env, jlangtag, -1, ampms, ampmType,
|
||||
0, AMPMTYPES, 0, FALSE);
|
||||
return ampms;
|
||||
}
|
||||
|
||||
|
@ -328,7 +311,7 @@ JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderA
|
|||
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonths
|
||||
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray months) {
|
||||
replaceCalendarArrayElems(env, jlangtag, -1, months, monthsType,
|
||||
0, MONTHTYPES, 0);
|
||||
0, MONTHTYPES, 0, TRUE);
|
||||
return months;
|
||||
}
|
||||
|
||||
|
@ -340,7 +323,7 @@ JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderA
|
|||
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getShortMonths
|
||||
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray smonths) {
|
||||
replaceCalendarArrayElems(env, jlangtag, -1, smonths, sMonthsType,
|
||||
0, MONTHTYPES, 0);
|
||||
0, MONTHTYPES, 0, TRUE);
|
||||
return smonths;
|
||||
}
|
||||
|
||||
|
@ -352,7 +335,7 @@ JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderA
|
|||
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getWeekdays
|
||||
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray wdays) {
|
||||
replaceCalendarArrayElems(env, jlangtag, -1, wdays, wDaysType,
|
||||
1, sizeof(wDaysType)/sizeof(CALTYPE), 0);
|
||||
1, DOWTYPES, 0, TRUE);
|
||||
return wdays;
|
||||
}
|
||||
|
||||
|
@ -364,7 +347,7 @@ JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderA
|
|||
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getShortWeekdays
|
||||
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray swdays) {
|
||||
replaceCalendarArrayElems(env, jlangtag, -1, swdays, sWDaysType,
|
||||
1, sizeof(sWDaysType)/sizeof(CALTYPE), 0);
|
||||
1, DOWTYPES, 0, TRUE);
|
||||
return swdays;
|
||||
}
|
||||
|
||||
|
@ -689,6 +672,30 @@ JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderA
|
|||
case CALENDAR_FIELD_ERA:
|
||||
return getErasImpl(env, jlangtag, calid, style, NULL);
|
||||
|
||||
case CALENDAR_FIELD_AM_PM:
|
||||
ret = (*env)->NewObjectArray(env, AMPMTYPES,
|
||||
(*env)->FindClass(env, "java/lang/String"), NULL);
|
||||
if (ret != NULL) {
|
||||
replaceCalendarArrayElems(env, jlangtag, calid, ret, ampmType,
|
||||
0, AMPMTYPES, style, FALSE);
|
||||
}
|
||||
return ret;
|
||||
|
||||
case CALENDAR_FIELD_DAY_OF_WEEK:
|
||||
ret = (*env)->NewObjectArray(env, DOWTYPES,
|
||||
(*env)->FindClass(env, "java/lang/String"), NULL);
|
||||
if (ret != NULL) {
|
||||
if (style & CALENDAR_STYLE_SHORT_MASK) {
|
||||
pCalType = sWDaysType;
|
||||
} else {
|
||||
pCalType = wDaysType;
|
||||
}
|
||||
|
||||
replaceCalendarArrayElems(env, jlangtag, calid, ret, pCalType,
|
||||
0, DOWTYPES, style, TRUE);
|
||||
}
|
||||
return ret;
|
||||
|
||||
case CALENDAR_FIELD_MONTH:
|
||||
ret = (*env)->NewObjectArray(env, MONTHTYPES,
|
||||
(*env)->FindClass(env, "java/lang/String"), NULL);
|
||||
|
@ -700,7 +707,7 @@ JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderA
|
|||
}
|
||||
|
||||
replaceCalendarArrayElems(env, jlangtag, calid, ret, pCalType,
|
||||
0, MONTHTYPES, style);
|
||||
0, MONTHTYPES, style, TRUE);
|
||||
}
|
||||
return ret;
|
||||
|
||||
|
@ -819,7 +826,7 @@ jint getCalendarID(const jchar *langtag) {
|
|||
return type;
|
||||
}
|
||||
|
||||
void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jint calid, jobjectArray jarray, CALTYPE* pCalTypes, int offset, int length, int style) {
|
||||
void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jint calid, jobjectArray jarray, DWORD* pTypes, int offset, int length, int style, BOOL bCal) {
|
||||
WCHAR name[BUFLEN];
|
||||
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
|
||||
jstring tmp_string;
|
||||
|
@ -839,8 +846,9 @@ void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jint calid, jobjec
|
|||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
if (getCalendarInfoWrapper(langtag, calid, NULL,
|
||||
pCalTypes[i] | isGenitive, name, BUFLEN, NULL) != 0) {
|
||||
if (bCal && getCalendarInfoWrapper(langtag, calid, NULL,
|
||||
pTypes[i] | isGenitive, name, BUFLEN, NULL) != 0 ||
|
||||
getLocaleInfoWrapper(langtag, pTypes[i] | isGenitive, name, BUFLEN) != 0) {
|
||||
tmp_string = (*env)->NewString(env, name, (jsize)wcslen(name));
|
||||
if (tmp_string != NULL) {
|
||||
(*env)->SetObjectArrayElement(env, jarray, i + offset, tmp_string);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue