-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8327640: Allow NumberFormat strict parsing #18339
8327640: Allow NumberFormat strict parsing #18339
Conversation
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
@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 14 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 |
@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
|
Replace setLenient() with setStrict() to avoid messy inversion of boolean. Add a leniency section to NumberFormat. Overhaul of NumberFormat class specification to be much more organized/readable.
gotPositive = text.regionMatches(position,positiveSuffix,0, | ||
positiveSuffix.length()); | ||
boolean containsPosSuffix = | ||
text.regionMatches(position, positiveSuffix,0, positiveSuffix.length()); |
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.
text.regionMatches(position, positiveSuffix,0, positiveSuffix.length()); | |
text.regionMatches(position, positiveSuffix, 0, positiveSuffix.length()); |
gotNegative = text.regionMatches(position,negativeSuffix,0, | ||
negativeSuffix.length()); | ||
boolean containsNegSuffix = | ||
text.regionMatches(position, negativeSuffix,0, negativeSuffix.length()); |
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.
text.regionMatches(position, negativeSuffix,0, negativeSuffix.length()); | |
text.regionMatches(position, negativeSuffix, 0, negativeSuffix.length()); |
boolean containsNegSuffix = | ||
text.regionMatches(position, negativeSuffix,0, negativeSuffix.length()); | ||
boolean endsWithNegSuffix = | ||
containsNegSuffix && text.length() == position + negativeSuffix.length(); |
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.
containsNegSuffix && text.length() == position + negativeSuffix.length(); | |
containsNegSuffix && text.length() == position + negativeSuffix.length(); |
@@ -2438,7 +2479,7 @@ int subparseNumber(String text, int position, | |||
boolean isExponent, boolean[] status) { | |||
// process digits or Inf, find decimal position | |||
status[STATUS_INFINITE] = false; | |||
if (!isExponent && text.regionMatches(position,symbols.getInfinity(),0, | |||
if (!isExponent && text.regionMatches(position, symbols.getInfinity(),0, |
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.
if (!isExponent && text.regionMatches(position, symbols.getInfinity(),0, | |
if (!isExponent && text.regionMatches(position, symbols.getInfinity(), 0, |
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, this and the other suggestions you provided should be fixed.
- specify and throw UOE as default - override and implement in dFmt and cmpctNFmt parseStrict should be protected, and utilized by subclasses. The public methods should just serve as API.
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.
Looks good overall. Left some minor comments.
As to the tests, good to see those corner cases, but they should have unit tests for the new methods, i.e, isStrict()
and setStrict()
. Also I think equality/serialization for those methods should be examined.
import sun.util.locale.provider.LocaleProviderAdapter; | ||
import sun.util.locale.provider.ResourceBundleBasedAdapter; | ||
|
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.
Internal packages typically follow public packages.
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.
Fixed. (IntelliJ is adamant on having it that way, and even after I previously reverted it, it seems like it slipped through again. Oddly, it never used to do this, need to look at the settings)
@@ -2575,7 +2648,24 @@ int subparseNumber(String text, int position, | |||
} | |||
} | |||
return position; | |||
} | |||
|
|||
// Checks to make sure grouping size is not violated. Used when strict. |
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.
If it is only supposed to be used in strict
, might be helpful to put an assertion here.
|
||
// Calculates the index that violated the grouping size | ||
// Calculation is determined whether it was an under or over violation |
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.
Not quite sure what under/over violation
means here. Need more comments?
import sun.util.locale.provider.LocaleProviderAdapter; | ||
import sun.util.locale.provider.LocaleServiceProviderPool; | ||
|
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.
Same as above
* @since 23 | ||
*/ | ||
public boolean isStrict() { | ||
throw new UnsupportedOperationException(); |
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.
Some message might be helpful.
* @since 23 | ||
*/ | ||
public void setStrict(boolean strict) { | ||
throw new UnsupportedOperationException(); |
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.
Same here
Thank you for the review @naotoj. All of your comments should be reflected in the two previous commits. As for the test suggestions, I added to existing tests if possible, otherwise I created new test files to address your suggestions. The new DecimalFormat equality and serialization test can definitely have other qualities tested (beyond parseStrict), but perhaps that's best for a separate issue. |
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. Thanks for the changes.
/integrate |
Going to push as commit 941bee1.
Your commit was automatically rebased without conflicts. |
@justin-curtis-lu Pushed as commit 941bee1. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this PR and associated CSR which introduces strict parsing for NumberFormat.
The concrete subclasses that will utilize this leniency value are
DecimalFormat
andCompactNumberFormat
. Strict leniency allows for parsing to be used as an input validation technique for localized formatted numbers. The default leniency mode will remain lenient, and can only be set to strict through an intentionalsetLenient(boolean)
method call. Leniency operates differently based off the values returned byisGroupingUsed()
,getGroupingSize()
, andisParseIntegerOnly()
.Below is an example of the change, the CSR can be viewed for further detail.
The associated tests are all localized, and the data is converted properly during runtime.
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18339/head:pull/18339
$ git checkout pull/18339
Update a local copy of the PR:
$ git checkout pull/18339
$ git pull https://git.openjdk.org/jdk.git pull/18339/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18339
View PR using the GUI difftool:
$ git pr show -t 18339
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18339.diff
Webrev
Link to Webrev Comment