Blame SOURCES/8140344.patch

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