8132091: Clean up JAXP code that has dependency on Java version string
authorjoehw
Thu, 03 Dec 2015 11:42:25 -0800
changeset 34463 c269a10aca11
parent 34462 ce5b18ce2ed5
child 34464 26566f0fde9c
child 34554 20d95817d066
8132091: Clean up JAXP code that has dependency on Java version string Reviewed-by: lancea
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/Constants.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderImpl.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/SAXParserImpl.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java	Thu Dec 03 11:42:25 2015 -0800
@@ -221,27 +221,4 @@
     public static final String FEATURE_TRUE = "true";
     public static final String FEATURE_FALSE = "false";
 
-    /**
-     * Check if we're in jdk8 or above
-     */
-    public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
-
-    /*
-     * Check the major version of the current JDK against that specified
-     * in the parameter
-     *
-     * 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 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");
-        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/xalan/internal/xsltc/trax/TransformerFactoryImpl.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java	Thu Dec 03 11:42:25 2015 -0800
@@ -524,7 +524,7 @@
             _xmlSecurityManager.setSecureProcessing(value);
 
             // set external access restriction when FSP is explicitly set
-            if (value && XalanConstants.IS_JDK8_OR_ABOVE) {
+            if (value) {
                 _xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
                         State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
                 _xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET,
@@ -539,7 +539,6 @@
                 _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION,
                         FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE);
             }
-            return;
         }
         else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
             //in secure mode, let _useServicesMechanism be determined by the constructor
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/Constants.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/Constants.java	Thu Dec 03 11:42:25 2015 -0800
@@ -203,11 +203,6 @@
      */
     public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
 
-    /**
-     * Check if we're in jdk8 or above
-     */
-    public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
-
     //
     // Implementation limits: corresponding System Properties of the above
     // API properties
@@ -856,25 +851,6 @@
         ? new ArrayEnumeration(fgXercesProperties) : fgEmptyEnumeration;
     } // getXercesProperties():Enumeration
 
-    /*
-     * Check the major version of the current JDK against that specified
-     * in the parameter
-     *
-     * 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 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");
-        javaVersion = (javaVersion.matches("[1-9][0-9]*(\\.(0|[1-9][0-9]*))*\\-.*")) ?
-                          javaVersion.split("-|\\.")[0] :
-                          javaVersion.split("\\.", 3)[1];
-        return Integer.parseInt(javaVersion) >= compareTo;
-    }
-
     //
     // Classes
     //
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderImpl.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderImpl.java	Thu Dec 03 11:42:25 2015 -0800
@@ -184,13 +184,11 @@
              */
             if (features != null) {
                 Boolean temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
-                if (temp != null) {
-                    if (temp && Constants.IS_JDK8_OR_ABOVE) {
-                        fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
-                                State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
-                        fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_SCHEMA,
-                                State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
-                    }
+                if (temp != null && temp) {
+                    fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
+                            State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
+                    fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_SCHEMA,
+                            State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
                 }
             }
         }
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/SAXParserImpl.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/SAXParserImpl.java	Thu Dec 03 11:42:25 2015 -0800
@@ -164,14 +164,11 @@
             if (features != null) {
 
                 Boolean temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
-                if (temp != null) {
-                    if (temp && Constants.IS_JDK8_OR_ABOVE) {
-                        fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
-                                XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
-                        fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
-                                XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
-
-                    }
+                if (temp != null && temp) {
+                    fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
+                            XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
+                    fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
+                            XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
                 }
             }
         }
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java	Thu Dec 03 11:42:25 2015 -0800
@@ -427,12 +427,10 @@
 
             fSecurityManager.setSecureProcessing(value);
             if (value) {
-                if (Constants.IS_JDK8_OR_ABOVE) {
-                    fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
-                            XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
-                    fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
-                            XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
-                }
+                fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
+                        XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
+                fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
+                        XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
             }
 
             fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java	Wed Dec 02 09:36:44 2015 -0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java	Thu Dec 03 11:42:25 2015 -0800
@@ -364,7 +364,7 @@
             fInitSecurityManager.setSecureProcessing(value);
             setProperty(SECURITY_MANAGER, fInitSecurityManager);
 
-            if (value && Constants.IS_JDK8_OR_ABOVE) {
+            if (value) {
                 fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
                         XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
                 fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,