JDK-8061673 : Refactor similar code for rounding mode handling in NumberFormat
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-10-21
  • Updated: 2019-04-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Related Reports
Relates :  
The handling of certain rounding modes in NumberFormat, say UP and DOWN, has very similar structure. Maintenance of the code would be eased and the code clarified if the similar cases were combined.
While working on 8039915, I also tested merging completely the 3 HALF_UP,HALF_EVEN, HALF_DOWN cases inside one switch branch. That worked perfectly well and all tests passed. All these three rounding moda have the same behaviour with regards to being above or below the tie. The difference is only happening when exactly on the tie. So the rounding behaviour is mostly the same except when on the tie. Thus it makes much sense to go one step further than 8039915 and merge HALF_EVEN with HALF_UP and HALF_DOWN. That would in addition improve a lot understandability and maintanability. I strongly recommend to merge the 3 HALF_* case to have consistent rounding code throughout all rounding modes. One thing that must be checked however is that the current ending loop of the HALF_EVEN case is not needed at all for all number cases. I checked that for all numbers in the integer magnitude, but not outside and also not when in an exponentiation plus input coming from non float/double values.

See comments in: http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-September/028872.html