Skip to content

ICU-23265 Fixed parseMeasureUnitOption() so that it correctly handles…#3910

Merged
richgillam merged 1 commit intounicode-org:mainfrom
richgillam:ICU-23265-unit-aliases
Mar 20, 2026
Merged

ICU-23265 Fixed parseMeasureUnitOption() so that it correctly handles…#3910
richgillam merged 1 commit intounicode-org:mainfrom
richgillam:ICU-23265-unit-aliases

Conversation

@richgillam
Copy link
Contributor

@richgillam richgillam commented Mar 18, 2026

… measurement unit aliases.

The idea here is to fix it so that NumberFormat::forSkeleton() doesn't return a syntax error when the skeleton includes a measurement unit that has been renamed, such as concentr-permillion. The idea is to maintain backward compatibility.

Checklist

  • Required: Issue filed: ICU-23265
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable
  • Approver: Feel free to merge on my behalf

@richgillam richgillam requested review from sffc and younies March 18, 2026 23:43
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider changing the impl of MeasureUnit::validateAndGet ?

@markusicu markusicu self-requested a review March 19, 2026 16:01
@richgillam
Copy link
Contributor Author

Did you consider changing the impl of MeasureUnit::validateAndGet ?

Yes, but not for very long. I was back-porting a fix I'd already made in Apple ICU, and validateAndGet() didn't exist at that time. I opted to keep my original fix as intact as I could, rather than trying to re-think it. I don't have a lot of time, and I'm uncomfortable in this code base. I was kind of hoping that if the fix wasn't good enough, somebody who knew the code better than I do (such as you or Younies) would be able to give me more specific instructions on what a better fix would look like. I'll take another look and see I can see an easy way to incorporate this change into that function, but if it's not fairly simple and straightforward, I'd like permission to leave it this way and let somebody else clean it up later.

@richgillam
Copy link
Contributor Author

Did you consider changing the impl of MeasureUnit::validateAndGet ?

Okay, I went back and took another look, and it actually wasn't that bad to move the alias handling code into validateAndGet(), so I did it and I hope you'll take another look.

This wound up being a Java-only fix because there is no Java version of MeasureUnit::validateAndGet() as far as I could tell, and the equivalent method-- MeasureUnit.getUnit()-- didn't look like a safe place to insert the alias-handling logic.

I think this commit should also fix the mvn spotless errors I was getting with my initial commit...

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better, thanks. To keep C++ and Java aligned, I think I'd rather see the Java change pulled into a new function MeasureUnit.validateAndGet that looks like the C++ function.

@richgillam
Copy link
Contributor Author

This is better, thanks. To keep C++ and Java aligned, I think I'd rather see the Java change pulled into a new function MeasureUnit.validateAndGet that looks like the C++ function.

Done.

@richgillam richgillam force-pushed the ICU-23265-unit-aliases branch from 43724d5 to 25499e3 Compare March 19, 2026 22:02
@jira-pull-request-webhook
Copy link

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

if (result == null) {
try {
result = MeasureUnit.forIdentifier(subtype);
if (!result.getType().equals(type)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation: you don't have if (!result.getType().equals(type)) in the C++ code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do. The check for typeIdx >= 0 on line 2774 is doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you're right. I don't have that exact check. I'll add it...

@richgillam
Copy link
Contributor Author

In case anybody's wondering, mvn spotless:check fails miserably for me, with a whole bunch of NoClassDefFoundErrors, most complaining about JCTree$JCAnyPattern. I'm guessing a versioning issue of some kind (or maybe a JDK issue?), but that's why there are all these extra commits to fix Java style-checker issues.

@richgillam richgillam force-pushed the ICU-23265-unit-aliases branch from f918639 to 884497d Compare March 20, 2026 01:07
@jira-pull-request-webhook
Copy link

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

@richgillam richgillam merged commit a7fd0e0 into unicode-org:main Mar 20, 2026
107 checks passed
@richgillam richgillam deleted the ICU-23265-unit-aliases branch March 20, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants