On Tue, 13 Apr 2021 11:42:41 GMT, Jaikiran Pai <j...@openjdk.org> wrote:
> Can I please get a review for this proposed fix for > https://bugs.openjdk.java.net/browse/JDK-8262108? > > As noted in a comment in that issue, the bug relates to the return value of > `Calendar.getDisplayNames` for the `Calendar.AM_PM` field. The implementation > has started returning invalid values for the `AM_PM` field after the "day > period" support was added recently in the JDK as part of > https://bugs.openjdk.java.net/browse/JDK-8262108. > > The commit here adds a check in the internal implementation of the display > name handling logic, to special case the `AM_PM` field and properly convert > the display name array indexes (which is an internal detail) to valid values > that represent the `AM_PM` calendar field. > > The commit also has a new jtreg test case `CalendarDisplayNamesTest` > reproduces this issue and verifies the fix. > > After this fix was introduced, I ran the test in > `test/jdk/java/util/Calendar/` and that showed up a failure in an existing > test case `NarrowNamesTest`. Looking at that test case, IMO, the current > testing in that `NarrowNamesTest` is incorrect and is probably what hid this > issue in the first place? To fix this, I have added an additional commit > which updates this test case to properly test the `AM_PM` field values. src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java line 201: > 199: switch (i) { > 200: case 0, 2, 3, 4, 5 -> map.put(name, > AM); > 201: case 1, 6, 7, 8, 9, 10, 11 -> > map.put(name, PM); One part where I need input here, is the "midnight" and the "noon" types. I haven't found anything in the JDK code which I can use as a reference to classify "midnight" and "noon" as `AM` (which is what this code is doing). The doc here https://unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rules speaks about these 2 types but I don't think it's something that I can use to translate those types into a field value for Calendar, to represent `AM` or `PM`. As such, right now, I've just guessed that `AM` is probably the right value for these types, but there's no technical reason or reference backing it. ------------- PR: https://git.openjdk.java.net/jdk/pull/3463