Blob Blame History Raw
# HG changeset patch
# User robm
# Date 1469137650 -3600
#      Thu Jul 21 22:47:30 2016 +0100
# Node ID c2ba29a6b98f628737ea1f74dd8745e4f72858a9
# Parent  048f6b9603cfcdd204b540a27fad8b7fc492adc2
8140344: add support for 3 digit update release numbers
Reviewed-by: coffeys

diff --git a/src/share/classes/sun/misc/Version.java.template b/src/share/classes/sun/misc/Version.java.template
--- openjdk/jdk/src/share/classes/sun/misc/Version.java.template
+++ openjdk/jdk/src/share/classes/sun/misc/Version.java.template
@@ -283,15 +283,24 @@
                 jvm_minor_version = Character.digit(cs.charAt(2), 10);
                 jvm_micro_version = Character.digit(cs.charAt(4), 10);
                 cs = cs.subSequence(5, cs.length());
-                if (cs.charAt(0) == '_' && cs.length() >= 3 &&
-                    Character.isDigit(cs.charAt(1)) &&
-                    Character.isDigit(cs.charAt(2))) {
-                    int nextChar = 3;
+                if (cs.charAt(0) == '_' && cs.length() >= 3) {
+                    int nextChar = 0;
+                    if (Character.isDigit(cs.charAt(1)) &&
+                        Character.isDigit(cs.charAt(2)) &&
+                        Character.isDigit(cs.charAt(3)))
+                    {
+                        nextChar = 4;
+                    } else if (Character.isDigit(cs.charAt(1)) &&
+                        Character.isDigit(cs.charAt(2)))
+                    {
+                        nextChar = 3;
+                    }
+
                     try {
-                        String uu = cs.subSequence(1, 3).toString();
+                        String uu = cs.subSequence(1, nextChar).toString();
                         jvm_update_version = Integer.valueOf(uu).intValue();
-                        if (cs.length() >= 4) {
-                            char c = cs.charAt(3);
+                        if (cs.length() >= nextChar + 1) {
+                            char c = cs.charAt(nextChar);
                             if (c >= 'a' && c <= 'z') {
                                 jvm_special_version = Character.toString(c);
                                 nextChar++;
diff --git a/src/share/native/common/jdk_util.c b/src/share/native/common/jdk_util.c
--- openjdk/jdk/src/share/native/common/jdk_util.c
+++ openjdk/jdk/src/share/native/common/jdk_util.c
@@ -52,6 +52,7 @@
 
     const char* jdk_update_string = JDK_UPDATE_VERSION;
     unsigned int jdk_update_version = 0;
+    int len_update_ver = 0;
     char update_ver[3];
     char jdk_special_version = '\0';
 
@@ -78,16 +79,17 @@
 
     assert(jdk_build_number >= 0 && jdk_build_number <= 255);
 
-    if (strlen(jdk_update_string) == 2 || strlen(jdk_update_string) == 3) {
-        if (isdigit(jdk_update_string[0]) && isdigit(jdk_update_string[1])) {
-            update_ver[0] = jdk_update_string[0];
-            update_ver[1] = jdk_update_string[1];
-            update_ver[2] = '\0';
-            jdk_update_version = (unsigned int) atoi(update_ver);
-            if (strlen(jdk_update_string) == 3) {
-                jdk_special_version = jdk_update_string[2];
-            }
+    len_update_ver = strlen(jdk_update_string);
+    if (len_update_ver >= 2 && len_update_ver <= 4) {
+        int update_digits = len_update_ver;
+
+        if (!isdigit(jdk_update_string[len_update_ver - 1])) {
+            jdk_special_version = jdk_update_string[len_update_ver -1];
+            update_digits = len_update_ver - 1;
         }
+        strncpy(update_ver, jdk_update_string, update_digits);
+        update_ver[update_digits] = '\0';
+        jdk_update_version = (unsigned int) atoi(update_ver);
     }
 
     memset(info, 0, info_size);
diff --git a/test/sun/misc/Version/Version.java b/test/sun/misc/Version/Version.java
--- openjdk/jdk/test/sun/misc/Version/Version.java
+++ openjdk/jdk/test/sun/misc/Version/Version.java
@@ -114,7 +114,7 @@
         regex +=   "([0-9]{1,2})";          // micro
         regex += ")?";                      // micro is optional
         regex += "(_";
-        regex +=   "([0-9]{2})";            // update
+        regex +=   "([0-9]{2,3})";          // update
         regex +=   "([a-z])?";              // special char (optional)
         regex += ")?";                      // _uu[c] is optional
         regex += ".*";                      // -<identifier>
@@ -132,33 +132,38 @@
         build = Integer.parseInt(m.group(9));
 
         VersionInfo vi = new VersionInfo(major, minor, micro, update, special, build);
-        System.out.printf("newVersionInfo: input=%s output=%s\n", version, vi);
+        System.out.printf("jdkVersionInfo: input=%s output=%s\n", version, vi);
         return vi;
     }
 
     private static VersionInfo jvmVersionInfo(String version) throws Exception {
-        // valid format of the version string is:
-        // <major>.<minor>-bxx[-<identifier>][-<debug_flavor>]
-        int major = 0;
-        int minor = 0;
-        int build = 0;
+        try {
+            // valid format of the version string is:
+            // <major>.<minor>-bxx[-<identifier>][-<debug_flavor>]
+            int major = 0;
+            int minor = 0;
+            int build = 0;
 
-        String regex = "^([0-9]{1,2})";     // major
-        regex += "\\.";                     // separator
-        regex += "([0-9]{1,2})";            // minor
-        regex += "(\\-b([0-9]{1,3}))";      // JVM -bxx
-        regex += ".*";
+            String regex = "^([0-9]{1,2})";     // major
+            regex += "\\.";                     // separator
+            regex += "([0-9]{1,2})";            // minor
+            regex += "(\\-b([0-9]{1,3}))";      // JVM -bxx
+            regex += ".*";
 
-        Pattern p = Pattern.compile(regex);
-        Matcher m = p.matcher(version);
-        m.matches();
+            Pattern p = Pattern.compile(regex);
+            Matcher m = p.matcher(version);
+            m.matches();
 
-        major = Integer.parseInt(m.group(1));
-        minor = Integer.parseInt(m.group(2));
-        build = Integer.parseInt(m.group(4));
+            major = Integer.parseInt(m.group(1));
+            minor = Integer.parseInt(m.group(2));
+            build = Integer.parseInt(m.group(4));
 
-        VersionInfo vi = new VersionInfo(major, minor, 0, 0, "", build);
-        System.out.printf("newVersionInfo: input=%s output=%s\n", version, vi);
-        return vi;
+            VersionInfo vi = new VersionInfo(major, minor, 0, 0, "", build);
+            System.out.printf("jvmVersionInfo: input=%s output=%s\n", version, vi);
+            return vi;
+        } catch (IllegalStateException e) {
+            // local builds may also follow the jdkVersionInfo format
+            return jdkVersionInfo(version);
+        }
     }
 }