JDK-8273814 : Duration.parse() parse '-0' and '0' to same result 0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2021-09-14
  • Updated: 2021-09-15
  • Resolved: 2021-09-15
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Mac OS 11.4

A DESCRIPTION OF THE PROBLEM :
Duration.parse()  parse 'PT-0.999S' to 'PT0.999S',because Long.parseLong() method parse '-0' and '0' to same result 0  .

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
 String text = "PT-0.999S";
 Duration d = Duration.parse(text);
 assert  d.toString().equals(text);

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no error
ACTUAL -
assert error

---------- BEGIN SOURCE ----------
 String text = "PT-0.999S";
 Duration d = Duration.parse(text);
 assert  d.toString().equals(text);
---------- END SOURCE ----------

FREQUENCY : always



Comments
Cannot reproduce with the latest release (JDK17). Possibly fixed by JDK-8054978.
15-09-2021

Instead of using the value returned from toString method to compare the original string, the returned string from toString needs to be converted to the same format as the original one. The observation on Windows 10: JDK 8: Failled, returned false. This incident can be closed as not an issue or changed to enhancement.
15-09-2021