8216969: ParseException thrown for certain months with russian locale
Reviewed-by: rriggs
This commit is contained in:
parent
bc920bd00d
commit
0623444ae5
src/java.base/share/classes/java/text
test/jdk/java/text/Format/DateFormat
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -1189,7 +1189,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PATTERN_MONTH: // 'M' (context seinsive)
|
case PATTERN_MONTH: // 'M' (context sensitive)
|
||||||
if (useDateFormatSymbols) {
|
if (useDateFormatSymbols) {
|
||||||
String[] months;
|
String[] months;
|
||||||
if (count >= 4) {
|
if (count >= 4) {
|
||||||
@ -2033,7 +2033,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Map<String, Integer> map = getDisplayNamesMap(field, locale);
|
Map<String, Integer> map = getDisplayContextNamesMap(field, locale);
|
||||||
if ((index = matchString(text, start, field, map, calb)) > 0) {
|
if ((index = matchString(text, start, field, map, calb)) > 0) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@ -2449,6 +2449,22 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
return map;
|
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
|
* After reading an object from the input stream, the format
|
||||||
* pattern in the object is verified.
|
* pattern in the object is verified.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4052223 4089987 4469904 4326988 4486735 8008577 8045998 8140571
|
* @bug 4052223 4089987 4469904 4326988 4486735 8008577 8045998 8140571
|
||||||
|
* 8216969
|
||||||
* @summary test DateFormat and SimpleDateFormat.
|
* @summary test DateFormat and SimpleDateFormat.
|
||||||
* @library /java/text/testlib
|
* @library /java/text/testlib
|
||||||
* @modules jdk.localedata
|
* @modules jdk.localedata
|
||||||
@ -1205,4 +1206,18 @@ test commented out pending API-change approval
|
|||||||
TimeZone.setDefault(initialTimeZone);
|
TimeZone.setDefault(initialTimeZone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Test8216969() throws Exception {
|
||||||
|
Locale locale = new Locale("ru");
|
||||||
|
String format = "\u0434\u0435\u043a";
|
||||||
|
String standalone = "\u0434\u0435\u043a.";
|
||||||
|
|
||||||
|
// Check that format form is used so that the dot is parsed correctly.
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM.yyyy", locale);
|
||||||
|
System.out.println(simpleDateFormat.parse("28 " + format + ".2018"));
|
||||||
|
|
||||||
|
// Check that standalone form is used.
|
||||||
|
simpleDateFormat = new SimpleDateFormat("MMM", locale);
|
||||||
|
System.out.println(simpleDateFormat.parse(standalone));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user