Skip to content

Commit

Permalink
8129572: Cleanup usage of getResourceAsStream in jaxp
Browse files Browse the repository at this point in the history
Reviewed-by: andrew
Backport-of: 4ebbfc918f558e73c05f471cfd3ab2b11dcf5a75
  • Loading branch information
akashche committed Mar 22, 2022
1 parent 969f31e commit bb69732
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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;
Expand Down Expand Up @@ -116,33 +115,6 @@ public Object run() throws FileNotFoundException {
}
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,10 @@ public Object run() throws FileNotFoundException {
}
}

/**
* 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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,6 @@ public Object run() throws FileNotFoundException {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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;
Expand Down Expand Up @@ -114,23 +113,6 @@ public Object run() throws FileNotFoundException {
}
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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;
Expand Down Expand Up @@ -114,23 +113,6 @@ public Object run() throws FileNotFoundException {
}
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,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;

/**
Expand Down Expand Up @@ -68,7 +66,7 @@ public XObject execute(XPathContext xctxt) throws javax.xml.transform.Transforme
// property argument is to be looked for.
Properties xsltInfo = new Properties();

loadPropertyFile(XSLT_PROPERTIES, xsltInfo);
loadPropertyFile(xsltInfo);

if (indexOfNSSep > 0)
{
Expand Down Expand Up @@ -158,25 +156,21 @@ public XObject execute(XPathContext xctxt) throws javax.xml.transform.Transforme
}

/**
* 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)
{
Expand Down
19 changes: 0 additions & 19 deletions jaxp/src/javax/xml/datatype/SecuritySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -77,23 +75,6 @@ public Object run() throws FileNotFoundException {
}
}

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() {
Expand Down
19 changes: 0 additions & 19 deletions jaxp/src/javax/xml/parsers/SecuritySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -81,23 +79,6 @@ public Object run() throws FileNotFoundException {
}
}

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() {
Expand Down
19 changes: 0 additions & 19 deletions jaxp/src/javax/xml/stream/SecuritySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -81,23 +79,6 @@ public Object run() throws FileNotFoundException {
}
}

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() {
Expand Down
19 changes: 0 additions & 19 deletions jaxp/src/javax/xml/transform/SecuritySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -79,23 +77,6 @@ public Object run() throws FileNotFoundException {
}
}

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() {
Expand Down
18 changes: 0 additions & 18 deletions jaxp/src/javax/xml/validation/SecuritySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.IOException;
import java.net.URL;
import java.security.*;
import java.net.*;
import java.io.*;
import java.util.*;

Expand Down Expand Up @@ -134,23 +133,6 @@ public Object run() throws IOException{
}
}

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() {
Expand Down
Loading

1 comment on commit bb69732

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.