changeset 31284:e9b8469adb9a

8129572: Cleanup usage of getResourceAsStream in jaxp Reviewed-by: alanb, joehw, mchung, redestad
author dfuchs
date Tue, 23 Jun 2015 19:50:10 +0200
parents 43d0179ee9de
children 2dec844adc37
files jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/SecuritySupport.java jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/SecuritySupport.java jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/SecuritySupport.java jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serialize/SecuritySupport.java jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java jaxp/src/java.xml/share/classes/javax/xml/datatype/SecuritySupport.java jaxp/src/java.xml/share/classes/javax/xml/parsers/SecuritySupport.java jaxp/src/java.xml/share/classes/javax/xml/stream/SecuritySupport.java jaxp/src/java.xml/share/classes/javax/xml/transform/SecuritySupport.java jaxp/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java jaxp/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java jaxp/src/java.xml/share/classes/org/xml/sax/helpers/SecuritySupport.java jaxp/test/javax/xml/jaxp/unittest/org/w3c/dom/ls/LSSerializerTest.java
diffstat 14 files changed, 17 insertions(+), 239 deletions(-) [+]
line wrap: on
line diff
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/util/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -24,7 +24,6 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
-import java.io.InputStream;
 import java.lang.ClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -116,33 +115,6 @@
     }
 
     /**
-     * Return resource using the same classloader for the ObjectFactory by
-     * default or bootclassloader when Security Manager is in place
-     */
-    public static InputStream getResourceAsStream(final String name) {
-        if (System.getSecurityManager() != null) {
-            return getResourceAsStream(null, name);
-        } else {
-            return getResourceAsStream(findClassLoader(), name);
-        }
-    }
-
-    public static InputStream getResourceAsStream(final ClassLoader cl,
-            final String name) {
-        return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                InputStream ris;
-                if (cl == null) {
-                    ris = Object.class.getResourceAsStream("/" + name);
-                } else {
-                    ris = cl.getResourceAsStream(name);
-                }
-                return ris;
-            }
-        });
-    }
-
-    /**
      * Gets a resource bundle using the specified base name, the default locale,
      * and the caller's class loader.
      *
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -128,29 +128,10 @@
         }
     }
 
-    /**
-     * Return resource using the same classloader for the ObjectFactory by
-     * default or bootclassloader when Security Manager is in place
-     */
     public static InputStream getResourceAsStream(final String name) {
-        if (System.getSecurityManager()!=null) {
-            return getResourceAsStream(null, name);
-        } else {
-            return getResourceAsStream(ObjectFactory.findClassLoader(), name);
-        }
-    }
-
-    public static InputStream getResourceAsStream(final ClassLoader cl,
-            final String name) {
         return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
             public Object run() {
-                InputStream ris;
-                if (cl == null) {
-                    ris = Object.class.getResourceAsStream("/"+name);
-                } else {
-                    ris = cl.getResourceAsStream(name);
-                }
-                return ris;
+                return SecuritySupport.class.getResourceAsStream("/"+name);
             }
         });
     }
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -118,34 +118,6 @@
             throw (FileNotFoundException)e.getException();
         }
     }
-    /**
-     * Return resource using the same classloader for the ObjectFactory by default
-     * or bootclassloader when Security Manager is in place
-     */
-    public static InputStream getResourceAsStream(final String name) {
-        if (System.getSecurityManager()!=null) {
-            return getResourceAsStream(null, name);
-        } else {
-            return getResourceAsStream(ObjectFactory.findClassLoader(), name);
-        }
-    }
-
-    public static InputStream getResourceAsStream(final ClassLoader cl,
-            final String name)
-    {
-        return (InputStream)
-        AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                InputStream ris;
-                if (cl == null) {
-                    ris = Object.class.getResourceAsStream("/"+name);
-                } else {
-                    ris = cl.getResourceAsStream(name);
-                }
-                return ris;
-            }
-        });
-    }
 
     /**
      * Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -23,7 +23,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.InputStream;
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -113,23 +112,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-            final String name)
-    {
-        return (InputStream)
-        AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                InputStream ris;
-                if (cl == null) {
-                    ris = ClassLoader.getSystemResourceAsStream(name);
-                } else {
-                    ris = cl.getResourceAsStream(name);
-                }
-                return ris;
-            }
-        });
-    }
-
     boolean getFileExists(final File f) {
         return ((Boolean)
                 AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serialize/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serialize/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -23,7 +23,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.InputStream;
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -113,23 +112,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-            final String name)
-    {
-        return (InputStream)
-        AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                InputStream ris;
-                if (cl == null) {
-                    ris = ClassLoader.getSystemResourceAsStream(name);
-                } else {
-                    ris = cl.getResourceAsStream(name);
-                }
-                return ris;
-            }
-        });
-    }
-
     boolean getFileExists(final File f) {
         return ((Boolean)
                 AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java	Tue Jun 23 19:50:10 2015 +0200
@@ -27,11 +27,9 @@
 import java.util.Properties;
 
 import com.sun.org.apache.xpath.internal.XPathContext;
-import com.sun.org.apache.xpath.internal.objects.XNumber;
 import com.sun.org.apache.xpath.internal.objects.XObject;
 import com.sun.org.apache.xpath.internal.objects.XString;
 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
-import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
 import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
 
 /**
@@ -69,7 +67,7 @@
     // property argument is to be looked for.
     Properties xsltInfo = new Properties();
 
-    loadPropertyFile(XSLT_PROPERTIES, xsltInfo);
+    loadPropertyFile(xsltInfo);
 
     if (indexOfNSSep > 0)
     {
@@ -159,25 +157,21 @@
   }
 
   /**
-   * Retrieve a propery bundle from a specified file
+   * Retrieve a property bundle from a XSLT_PROPERTIES
    *
-   * @param file The string name of the property file.  The name
-   * should already be fully qualified as path/filename
    * @param target The target property bag the file will be placed into.
    */
-  public void loadPropertyFile(String file, Properties target)
+  private void loadPropertyFile(Properties target)
   {
     try
     {
-      // Use SecuritySupport class to provide priveleged access to property file
-      InputStream is = SecuritySupport.getResourceAsStream(ObjectFactory.findClassLoader(),
-                                              file);
+      // Use SecuritySupport class to provide privileged access to property file
+      InputStream is = SecuritySupport.getResourceAsStream(XSLT_PROPERTIES);
 
       // get a buffered version
-      BufferedInputStream bis = new BufferedInputStream(is);
-
-      target.load(bis);  // and load up the property bag from this
-      bis.close();  // close out after reading
+      try (BufferedInputStream bis = new BufferedInputStream(is)) {
+          target.load(bis);  // and load up the property bag from this
+      }
     }
     catch (Exception ex)
     {
--- a/jaxp/src/java.xml/share/classes/javax/xml/datatype/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/javax/xml/datatype/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -26,9 +26,7 @@
 package javax.xml.datatype;
 
 import java.security.*;
-import java.net.*;
 import java.io.*;
-import java.util.*;
 
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
@@ -77,23 +75,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
     boolean doesFileExist(final File f) {
     return ((Boolean)
             AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/javax/xml/parsers/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/javax/xml/parsers/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -26,9 +26,7 @@
 package javax.xml.parsers;
 
 import java.security.*;
-import java.net.*;
 import java.io.*;
-import java.util.*;
 
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
@@ -81,23 +79,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
     boolean doesFileExist(final File f) {
     return ((Boolean)
             AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/javax/xml/stream/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/javax/xml/stream/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -26,9 +26,7 @@
 package javax.xml.stream;
 
 import java.security.*;
-import java.net.*;
 import java.io.*;
-import java.util.*;
 
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
@@ -81,23 +79,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
     boolean doesFileExist(final File f) {
     return ((Boolean)
             AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -26,9 +26,7 @@
 package javax.xml.transform;
 
 import java.security.*;
-import java.net.*;
 import java.io.*;
-import java.util.*;
 
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
@@ -79,23 +77,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
     boolean doesFileExist(final File f) {
     return ((Boolean)
             AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -28,7 +28,6 @@
 import java.io.IOException;
 import java.net.URL;
 import java.security.*;
-import java.net.*;
 import java.io.*;
 import java.util.*;
 
@@ -134,23 +133,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
     boolean doesFileExist(final File f) {
     return ((Boolean)
             AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -27,7 +27,6 @@
 
 import java.net.URL;
 import java.security.*;
-import java.net.*;
 import java.io.*;
 import java.util.*;
 
@@ -131,23 +130,6 @@
         }
     }
 
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
     boolean doesFileExist(final File f) {
     return ((Boolean)
             AccessController.doPrivileged(new PrivilegedAction() {
--- a/jaxp/src/java.xml/share/classes/org/xml/sax/helpers/SecuritySupport.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/org/xml/sax/helpers/SecuritySupport.java	Tue Jun 23 19:50:10 2015 +0200
@@ -87,7 +87,7 @@
                 public Object run() {
                     InputStream ris;
                     if (cl == null) {
-                        ris = Object.class.getResourceAsStream(name);
+                        ris = SecuritySupport.class.getResourceAsStream(name);
                     } else {
                         ris = cl.getResourceAsStream(name);
                     }
--- a/jaxp/test/javax/xml/jaxp/unittest/org/w3c/dom/ls/LSSerializerTest.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/unittest/org/w3c/dom/ls/LSSerializerTest.java	Tue Jun 23 19:50:10 2015 +0200
@@ -134,6 +134,9 @@
         DOMImplementation impl = doc.getImplementation();
         DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
         LSSerializer writer = implLS.createLSSerializer();
+
+        System.out.println("Serializer is: " + implLS.getClass().getName() + " " + implLS);
+
         DOMErrorHandlerImpl eh = new DOMErrorHandlerImpl();
         writer.getDomConfig().setParameter("error-handler", eh);
 
@@ -200,6 +203,8 @@
         DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation;
         LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
 
+        System.out.println("Serializer is: " + lsSerializer.getClass().getName() + " " + lsSerializer);
+
         // get configuration
         DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
 
@@ -294,6 +299,8 @@
         DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation;
         LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
 
+        System.out.println("Serializer is: " + lsSerializer.getClass().getName() + " " + lsSerializer);
+
         // get default serialization
         String defaultSerialization = lsSerializer.writeToString(document);