Details
-
Bug
-
Resolution: Unresolved
-
P4
-
None
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.
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.
Attachments
Issue Links
- relates to
-
JDK-8157260 (spec) Runtime.Version.version() should reference indices of List
-
- Open
-
-
JDK-8160564 TEST: Add a test to check the implementation of VersionProps.versionNumbers()
-
- Closed
-
-
JDK-8144062 Move jdk.Version to java.lang.Runtime.Version
-
- Closed
-