changeset 5774:a7dfa5fd2a89

8010166: TEST_BUG: fix for 8009634 overlooks possible version strings (sun/misc/Version/Version.java) Reviewed-by: kvn
author robm
date Tue, 19 Mar 2013 16:52:53 +0000
parents 74c9dbadcce8
children de4e41c5c549
files test/sun/misc/Version/Version.java
diffstat 1 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/misc/Version/Version.java	Fri Mar 15 01:43:04 2013 +0000
+++ b/test/sun/misc/Version/Version.java	Tue Mar 19 16:52:53 2013 +0000
@@ -35,7 +35,7 @@
 public class Version {
 
     public static void main(String[] args) throws Exception {
-        VersionInfo jdk = newVersionInfo(System.getProperty("java.runtime.version"));
+        VersionInfo jdk = jdkVersionInfo(System.getProperty("java.runtime.version"));
         VersionInfo v1 = new VersionInfo(jdkMajorVersion(),
                                          jdkMinorVersion(),
                                          jdkMicroVersion(),
@@ -46,7 +46,7 @@
         if (!jdk.equals(v1)) {
             throw new RuntimeException("Unmatched version: " + jdk + " vs " + v1);
         }
-        VersionInfo jvm = newVersionInfo(System.getProperty("java.vm.version"));
+        VersionInfo jvm = jvmVersionInfo(System.getProperty("java.vm.version"));
         VersionInfo v2 = new VersionInfo(jvmMajorVersion(),
                                          jvmMinorVersion(),
                                          jvmMicroVersion(),
@@ -97,9 +97,9 @@
         }
     }
 
-    private static VersionInfo newVersionInfo(String version) throws Exception {
+    private static VersionInfo jdkVersionInfo(String version) throws Exception {
         // valid format of the version string is:
-        // n.n.n[_uu[c]][-<identifer>]-bxx
+        // <major>.<minor>[.<micro>][_uu[c]][-<identifier>]-bxx
         int major = 0;
         int minor = 0;
         int micro = 0;
@@ -107,8 +107,7 @@
         String special = "";
         int build = 0;
 
-        // n.n.n[_uu[c]][-<identifer>]-bxx
-        String regex = "([0-9]{1,2})";      // major
+        String regex = "^([0-9]{1,2})";     // major
         regex += "\\.";                     // separator
         regex += "([0-9]{1,2})";            // minor
         regex += "(\\.";                    // separator
@@ -118,8 +117,8 @@
         regex +=   "([0-9]{2})";            // update
         regex +=   "([a-z])?";              // special char (optional)
         regex += ")?";                      // _uu[c] is optional
-        regex += "(\\-[a-z]{2,})?";         // -<identifier>
-        regex += "(\\-b([0-9]{1,2}))?";     // -bxx
+        regex += ".*";                      // -<identifier>
+        regex += "(\\-b([0-9]{1,3}$))";     // JDK -bxx
 
         Pattern p = Pattern.compile(regex);
         Matcher m = p.matcher(version);
@@ -130,10 +129,36 @@
         micro = (m.group(4) == null) ? 0 : Integer.parseInt(m.group(4));
         update = (m.group(6) == null) ? 0 : Integer.parseInt(m.group(6));
         special = (m.group(7) == null) ? "" : m.group(7);
-        build = Integer.parseInt(m.group(10));
+        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);
         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;
+
+        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();
+
+        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;
+    }
 }