8381644: Locale matching APIs handle null inputs inconsistently#30632
8381644: Locale matching APIs handle null inputs inconsistently#30632justin-curtis-lu wants to merge 1 commit intoopenjdk:masterfrom
Conversation
|
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@justin-curtis-lu The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
What if |
@naotoj You're right. I wanted to keep the checks out of the standard-path case if possible. But it looks like to ensure this behavior for an early match (and possible subsequent null elements later), we will need to validate all cases up-front. One alternative is weakening the specified NullPointerException to "may throw" for null elements within the collections, if the up-front performance cost is a concern. |
Yeah, this seems more accommodating. We could explicitly state in the spec that early matching is allowed. |
|
@naotoj Something to note is that for all APIs, the priority list is eagerly iterated on, so no null elements can be hidden there. The locale collection accepting APIs eagerly convert locales to tags as well, so the problem only arises for tags. The |
|
Or what if we "accept" null elements, which would be simply ignored? That would avoid NPE crash. |
This PR standardizes the null related behavior for the
Localefiltering and lookup APIs.There are two issues. First, null elements within either
Collectionwhich are passed to these APIs may cause NPE, but this is not specified. Second, if thetagsorlocaleslist is null andpriorityListempty, NPE is not thrown (even though it is specified to).For example, this is the current null related behavior for
Locale:lookup(List<LanguageRange>, Collection<Locale>)(where all cases should throw NPE),This update ensures that when either
Collectionis null, or any elements within are null, NPE is always thrown. That is, the empty edge case does not mask the NPE. The fix for null elements is done in the empty case conditional withinLocaleMatcher, since the standard cases naturally encounter NPE. The specification is updated to fill in the missing behavior. As this also creates a behavioral change (to match the expected API contract), a CSR is filed.Progress
Issues
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30632/head:pull/30632$ git checkout pull/30632Update a local copy of the PR:
$ git checkout pull/30632$ git pull https://git.openjdk.org/jdk.git pull/30632/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30632View PR using the GUI difftool:
$ git pr show -t 30632Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30632.diff
Using Webrev
Link to Webrev Comment