-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8321480: ISO 4217 Amendment 176 Update #17023
8321480: ISO 4217 Amendment 176 Update #17023
Conversation
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
@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. |
Webrevs
|
@@ -494,6 +494,7 @@ xbb=European Monetary Unit | |||
xbc=European Unit of Account (XBC) | |||
xbd=European Unit of Account (XBD) | |||
xcd=East Caribbean Dollar | |||
xcg=Caribbean Guilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think XCG=XCG
is also needed for not throwing MissingResourceException
for getSymbol()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the correction, added in.
} else { | ||
// Still need to add the future currency to testCurrencies | ||
// without updating ISO4217Codes | ||
String futureCurr = tokens.nextToken(); | ||
testCurrencies.add(Currency.getInstance(futureCurr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd not add the future currency, and fix it in the code not to add future currency in available currencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the Currency build process to disallow any Currencies that are future Currencies. This prevents the future currency, "XCG" from leaking out into Currency.getAvailableCurrencies()
. (This was only exposed now, since the previous future Currencies were already ones expected to be found in Currency.getAvailableCurrencies()
. For example, Amendment 174 where HRK was replaced by EUR.
(Tiers 1-5 clean with this change)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this should have happened before, as a currency update like "XXA" -> "XXB" on a future date is pretty usual. I think this issue was simply not discovered by any users till now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this wasn't discovered/hasn't failed the test before because the amendments with future date changes most of the time were implemented after the date already occurred, so there was no cut-over, simply a new currency directly replacing the old (For example, ISO 171 SLE replacing SLL was direct). In the case where the cut-over hadn't happened, like 174 where EUR replaced HRK, EUR is already expected to be returned by Currency.getAvailableCurrencies()
so there was no issue.
I claimed that this particular amendment exposed it, because if this case had happened before with an amendment update, it would have caused validateISO4217.java to fail (as it does with this case). Since that test checks if the set returned by the method does not contain any future currencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is rare but happened before. The test had failed with the cut-over date in the past. Possibly at that time, getAvailableCurrencies test may not have been there so it wasn't obvious when the modification was made.
@Test | ||
public void twoLetterCodesTest() { | ||
for (String country : codeCombos()) { | ||
if (codes[toIndex(country)] == UNDEFINED) { | ||
// if a code is undefined / 0, creating a Currency from it | ||
// should throw an IllegalArgumentException | ||
assertThrows(IllegalArgumentException.class, | ||
() -> Currency.getInstance(Locale.of("", country)), | ||
"Error: This should be an undefined code and throw IllegalArgumentException: " + country); | ||
} else if (codes[toIndex(country)] == SKIPPED) { | ||
// if a code is marked as skipped / 2, creating a Currency from it | ||
// should return null | ||
assertNull(Currency.getInstance(Locale.of("", country)), | ||
"Error: Currency.getInstance() for this locale should return null: " + country); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous output was overflowing due to the method being a @ParameterizedTest
since it was testing against 26*26 inputs. Changing to @Test
makes diagnostics easier, as there is no more overflow.
// Do not allow a future currency to be classified as an otherCurrency, | ||
// otherwise it will leak out into Currency:getAvailableCurrencies | ||
boolean notFutureCurrency = !Arrays.asList(specialCaseNewCurrencies).contains(currencyCode); | ||
boolean notSimpleCurrency = tableEntry == INVALID_COUNTRY_ENTRY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not bundle up those conditions into notSimpleCurrency
, as it obscures the other two cases. Simply OR-ing those conditions and notFutureCurrency
( or !futureCurrency
may be more readable) would be sufficient IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, at first I had intended for the notSimpleCurrency
to encapsulate all 3 cases. But upon further investigation, I think the current code is redundant.
The third conditional, (tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) != (currencyCode.charAt(2) - 'A')
checks if the currency's first two chars match the country code (which also implies the current currency is simple). It returns false if they match. When this is false, the other first two conditions are always false. If a currencyCode is simple, the countryCode is always defined, and the currencyCode itself is not special. Checking the first two AND the third seems redundant when the first two are always false if the third is false.
For example, take the currency ADP
which will search for the table entry of the country AD
. Since AD=EUR
, the third conditional returns true. We now know that we do not have a simple currency, which is more than enough to make a decision whether to add the current currency to the otherCurrency List. But the existing code now checks that AD
is a defined country and whether EUR
is special or not (since AD
's tableEntry value is associated with EUR
). I'm not sure why we would check that EUR
is a special currency, when we are deciding to add ADP
as an otherCurrency. It is hard to infer without any existing comments as well.
With commit 85f389d, the same exact values are added to the otherCurrency list. However, If we would prefer not to update such old code for the sake of safety, then I would at least like to add comments that warn which conditionals may be irrelevant. Wondering what your thoughts are regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you compare the built binary currency.data
before and after your change? If they are identical, I think we can go ahead and remove the redundancy in the tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will go ahead and compare, as well as do a few more sanity checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@justin-curtis-lu This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 21 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 8b24851.
Your commit was automatically rebased without conflicts. |
@justin-curtis-lu Pushed as commit 8b24851. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this PR which incorporates the ISO 4217 Amendment 176 Update. As the replacement of
ANG
toXCG
won't occur until 2025, this change does not need to go into JDK22.HR
was also updated to remove the past cutover dates.This update also demonstrated that
Currency::getAvailableCurrencies
may return a future currency that should not be returned. GenerateCurrencyData.java was updated to ensure such currencies are not added to the other currency list.Additionally, this change also converted a parameterized test to a normal JUnit test, due to output overflow.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17023/head:pull/17023
$ git checkout pull/17023
Update a local copy of the PR:
$ git checkout pull/17023
$ git pull https://git.openjdk.org/jdk.git pull/17023/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 17023
View PR using the GUI difftool:
$ git pr show -t 17023
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17023.diff
Webrev
Link to Webrev Comment