alhudz opened a new pull request, #1800:
URL: https://github.com/apache/commons-lang/pull/1800
`FastDatePrinter.parsePattern` builds the `G` rule from
`DateFormatSymbols.getEras()`, a two-entry Gregorian table, but the printer
formats with `Calendar.getInstance(timeZone, locale)`, which is the Thai
Buddhist calendar for `th_TH` and the Japanese Imperial calendar for
`ja_JP_JP`. The year comes from that calendar and the era label from the
Gregorian table, so `FastDateFormat.getInstance("G yyyy", th_TH)` prints `ค.ศ.
2567` (AD 2567) where `SimpleDateFormat` prints `พ.ศ. 2567`, and
`parse(format(date))` then throws `ParseException` because `FastDateParser`
takes its era names from the calendar. For `ja_JP_JP` the Reiwa era value is 5,
so `format` throws `ArrayIndexOutOfBoundsException` from `TextField.appendTo`.
Take the era names from the printer's own calendar when its type is not
`gregory`, sized to `Calendar.getMaximum(ERA)` and using the long names for
`GGGG` as `SimpleDateFormat` does; Gregorian locales keep
`DateFormatSymbols.getEras()` so their output is unchanged. This is the only
era lookup in the library, and the other symbol tables (months, weekdays,
am/pm) are shared by all three calendars. The `yyyy` padding of the Imperial
year still differs from `SimpleDateFormat` (`0006` against `6`); that is the
year rule and is left alone here.
Repro:
```java
FastDateFormat.getInstance("G yyyy", TimeZones.GMT, new Locale("ja", "JP",
"JP")).format(date20240501);
```
Expected: `令和 0006`, and `parse` accepts it again.
Actual: `ArrayIndexOutOfBoundsException: Index 5 out of bounds for length
2`; the `th_TH` form prints `ค.ศ. 2567` and no longer parses.
---
Thanks for your contribution to [Apache
Commons](https://commons.apache.org/)! Your help is appreciated!
Before you push a pull request, review this list:
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute? Claude Code (Anthropic) helped find the defect and draft the patch
and tests; I reviewed the change and ran the build and tests locally.
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied. This may not always be possible,
but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body. Note that a maintainer may squash commits during the merge process.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]