On Tue, 27 Oct 2026 20:15:37 GMT, Justin Lu <[email protected]> wrote:
> This issue originally came in as a performance suggestion to replace the > regex based validation with an ASCII check for `getInstance(Locale)`. > > However, the current regex validation does not even appear like it is > required at all, since `getMainTableEntry` already returns > `INVALID_COUNTRY_ENTRY` for invalid characters, correctly leading to `IAE`. > Additionally, the `null` check looks incorrect because > `BaseLocale.getCountry()` is specified to return the empty String, not > `null`. `getCountry()` also returns the country code in uppercase. > > All we need to do is check the length to ensure that a country exists and > that it is in the form of a ISO 3166 2-letter code instead of a UN M.49 3 > digit code. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). src/java.base/share/classes/java/util/Currency.java line 397: > 395: > 396: String country = > CalendarDataUtility.findRegionOverride(locale).getCountry(); > 397: if (country.length() != 2) { I think an ASCII range check is still needed here (no need for regex). Otherwise, invalid country codes such as "C1" will end up throwing an IAE with a different error message in `getMainTableEntry`, which only includes the invalid country code. That would be missing other input locale information, eg its language code. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/33594#discussion_r4394405791
