8098588: Allow for parsing jdk9 new version string
authoramurillo
Mon, 22 Jun 2015 13:04:01 -0700
changeset 34044 4c5494af1359
parent 31008 5b500c93ce48
child 34045 fd54aa99f3eb
8098588: Allow for parsing jdk9 new version string Reviewed-by: alanb, joehw, dtitov
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/Constants.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java	Wed Jul 05 20:37:12 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java	Mon Jun 22 13:04:01 2015 -0700
@@ -227,24 +227,21 @@
     public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
 
     /*
-     * Check the version of the current JDK against that specified in the
-     * parameter
+     * Check the major version of the current JDK against that specified
+     * in the parameter
      *
-     * There is a proposal to change the java version string to:
-     * MAJOR.MINOR.FU.CPU.PSU-BUILDNUMBER_BUGIDNUMBER_OPTIONAL
-     * This method would work with both the current format and that proposed
+     * In JDK9 the java version string was changed to comply with JEP-223
+     * so this method was modified to handle that new format as well
      *
-     * @param compareTo a JDK version to be compared to
-     * @return true if the current version is the same or above that represented
-     * by the parameter
+     * @param compareTo a JDK major version to be compared to
+     * @return true if the current major version is the same or above
+     * that represented by the parameter
      */
     public static boolean isJavaVersionAtLeast(int compareTo) {
         String javaVersion = SecuritySupport.getSystemProperty("java.version");
-        String versions[] = javaVersion.split("\\.", 3);
-        if (Integer.parseInt(versions[0]) >= compareTo ||
-            Integer.parseInt(versions[1]) >= compareTo) {
-            return true;
-        }
-        return false;
+        javaVersion = (javaVersion.matches("[1-9][0-9]*(\\.(0|[1-9][0-9]*))*\\-.*")) ?
+                          javaVersion.split("-|\\.")[0] :
+                          javaVersion.split("\\.", 3)[1];
+        return Integer.parseInt(javaVersion) >= compareTo;
     }
 } // class Constants
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/Constants.java	Wed Jul 05 20:37:12 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/Constants.java	Mon Jun 22 13:04:01 2015 -0700
@@ -857,25 +857,22 @@
     } // getXercesProperties():Enumeration
 
     /*
-     * Check the version of the current JDK against that specified in the
-     * parameter
+     * Check the major version of the current JDK against that specified
+     * in the parameter
      *
-     * There is a proposal to change the java version string to:
-     * MAJOR.MINOR.FU.CPU.PSU-BUILDNUMBER_BUGIDNUMBER_OPTIONAL
-     * This method would work with both the current format and that proposed
+     * In JDK9 the java version string was changed to comply with JEP-223
+     * so this method was modified to handle that new format as well
      *
-     * @param compareTo a JDK version to be compared to
-     * @return true if the current version is the same or above that represented
-     * by the parameter
+     * @param compareTo a JDK major version to be compared to
+     * @return true if the current major version is the same or above
+     * that represented by the parameter
      */
     public static boolean isJavaVersionAtLeast(int compareTo) {
         String javaVersion = SecuritySupport.getSystemProperty("java.version");
-        String versions[] = javaVersion.split("\\.", 3);
-        if (Integer.parseInt(versions[0]) >= compareTo ||
-            Integer.parseInt(versions[1]) >= compareTo) {
-            return true;
-        }
-        return false;
+        javaVersion = (javaVersion.matches("[1-9][0-9]*(\\.(0|[1-9][0-9]*))*\\-.*")) ?
+                          javaVersion.split("-|\\.")[0] :
+                          javaVersion.split("\\.", 3)[1];
+        return Integer.parseInt(javaVersion) >= compareTo;
     }
 
     //