8216969: ParseException thrown for certain months with russian locale

Reviewed-by: rriggs
This commit is contained in:
Naoto Sato 2019-01-22 15:22:13 -08:00
parent bc920bd00d
commit 0623444ae5
2 changed files with 35 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@ -1189,7 +1189,7 @@ public class SimpleDateFormat extends DateFormat {
}
break;
case PATTERN_MONTH: // 'M' (context seinsive)
case PATTERN_MONTH: // 'M' (context sensitive)
if (useDateFormatSymbols) {
String[] months;
if (count >= 4) {
@ -2033,7 +2033,7 @@ public class SimpleDateFormat extends DateFormat {
return index;
}
} else {
Map<String, Integer> map = getDisplayNamesMap(field, locale);
Map<String, Integer> map = getDisplayContextNamesMap(field, locale);
if ((index = matchString(text, start, field, map, calb)) > 0) {
return index;
}
@ -2449,6 +2449,22 @@ public class SimpleDateFormat extends DateFormat {
return map;
}
/**
* Obtains display names map, taking the context into account. Currently only
* the month name pattern 'M' is context dependent.
*/
private Map<String, Integer> getDisplayContextNamesMap(int field, Locale locale) {
Map<String, Integer> map = calendar.getDisplayNames(field,
forceStandaloneForm ? Calendar.SHORT_STANDALONE : Calendar.SHORT_FORMAT, locale);
// Get the LONG style
Map<String, Integer> m = calendar.getDisplayNames(field,
forceStandaloneForm ? Calendar.LONG_STANDALONE : Calendar.LONG_FORMAT, locale);
if (m != null) {
map.putAll(m);
}
return map;
}
/**
* After reading an object from the input stream, the format
* pattern in the object is verified.