JDK-8156907 : Runtime.Version.{major(),security()} return value of 0 may be ambiguous
  • Type: Bug
  • Component: other-libs
  • Sub-Component: other
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2016-05-13
  • Updated: 2024-01-12
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.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
Version.major() and Version.security() will return 0 if those values are set to zero OR if they are unset.  If a user tries to construct a String which contains trialing zeros, and then invokes Version.parse(), this will fail, even if the source of the zeros was a valid Version object.  For example:

  Version v  = Version.parse("9");
  Version ver = Version.parse(String.format("%d.%d.%d%n), 
                                               v.major(), v.minor(), v.security()));  // IAE

If the current method signatures returning int are retained, constants NO_MINOR_VERSION and NO_MAJOR_VERSION (both = -1) could be returned instead of 0.

Alternatively, changing the methods' return value to Integer and returning null might be more palatable. 

If we re-consider how trialing zeros are handled, there are a number of additional options, some combination of which would address this problem or at least reduce impact.


Comments
JDK-8160564 adds a validation check for trailing zeros. This code will need to be revisited when this issue is resolved.
12-07-2016