changeset 16881:a2b8bf9a32ce

8176882: Incorrect integer comparison in version numbers Reviewed-by: psandoz
author prappo
date Thu, 16 Mar 2017 22:58:13 +0000
parents 45b226ad2e05
children f8089e07c9f2
files src/java.base/share/classes/java/lang/Runtime.java test/java/lang/Runtime/Version/Basic.java
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Runtime.java	Thu Mar 16 16:56:29 2017 -0400
+++ b/src/java.base/share/classes/java/lang/Runtime.java	Thu Mar 16 22:58:13 2017 +0000
@@ -1337,14 +1337,12 @@
             int oSize = ob.version().size();
             int min = Math.min(size, oSize);
             for (int i = 0; i < min; i++) {
-                Integer val = version.get(i);
-                Integer oVal = ob.version().get(i);
+                int val = version.get(i);
+                int oVal = ob.version().get(i);
                 if (val != oVal)
                     return val - oVal;
             }
-            if (size != oSize)
-                return size - oSize;
-            return 0;
+            return size - oSize;
         }
 
         private int comparePre(Version ob) {
--- a/test/java/lang/Runtime/Version/Basic.java	Thu Mar 16 16:56:29 2017 -0400
+++ b/test/java/lang/Runtime/Version/Basic.java	Thu Mar 16 22:58:13 2017 +0000
@@ -129,6 +129,9 @@
         testEHC("9",          "10",               false, false, -1,   -1);
         testEHC("9",          "8",                false, false,  1,    1);
 
+        testEHC("10.512.1",   "10.512.2",         false, false, -1,   -1);
+        testEHC("512.10.1",   "512.11.1",         false, false, -1,   -1);
+
         // $OPT comparison
         testEHC("9",          "9+-oink",          false, true,  -1,    0);
         testEHC("9+-ribbit",  "9+-moo",           false, true,   1,    0);