mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8130051: Cleanup usage of reflection in jaxp
Replaced usage of reflection with direct access where possible, removed obsolete code where possible. Reviewed-by: joehw
This commit is contained in:
parent
eb76b21f6d
commit
0c329ac4cf
23 changed files with 135 additions and 1236 deletions
|
@ -110,6 +110,12 @@ public class TransformerException extends Exception {
|
|||
*/
|
||||
public synchronized Throwable initCause(Throwable cause) {
|
||||
|
||||
// TransformerException doesn't set its cause (probably
|
||||
// because it predates initCause()) - and we may not want
|
||||
// to change this since Exceptions are serializable...
|
||||
// But this also leads to the broken code in printStackTrace
|
||||
// below...
|
||||
|
||||
if (this.containedException != null) {
|
||||
throw new IllegalStateException("Can't overwrite cause");
|
||||
}
|
||||
|
@ -312,61 +318,57 @@ public class TransformerException extends Exception {
|
|||
}
|
||||
|
||||
try {
|
||||
String locInfo = getLocationAsString();
|
||||
|
||||
if (null != locInfo) {
|
||||
s.println(locInfo);
|
||||
}
|
||||
|
||||
super.printStackTrace(s);
|
||||
} catch (Throwable e) {}
|
||||
|
||||
Throwable exception = getException();
|
||||
|
||||
for (int i = 0; (i < 10) && (null != exception); i++) {
|
||||
s.println("---------");
|
||||
|
||||
try {
|
||||
if (exception instanceof TransformerException) {
|
||||
String locInfo =
|
||||
((TransformerException) exception)
|
||||
.getLocationAsString();
|
||||
String locInfo = getLocationAsString();
|
||||
|
||||
if (null != locInfo) {
|
||||
s.println(locInfo);
|
||||
}
|
||||
if (null != locInfo) {
|
||||
s.println(locInfo);
|
||||
}
|
||||
|
||||
exception.printStackTrace(s);
|
||||
} catch (Throwable e) {
|
||||
s.println("Could not print stack trace...");
|
||||
}
|
||||
super.printStackTrace(s);
|
||||
} catch (Throwable e) {}
|
||||
|
||||
try {
|
||||
Method meth =
|
||||
((Object) exception).getClass().getMethod("getException",
|
||||
(Class[]) null);
|
||||
Throwable exception = getException();
|
||||
|
||||
if (null != meth) {
|
||||
Throwable prev = exception;
|
||||
for (int i = 0; (i < 10) && (null != exception); i++) {
|
||||
s.println("---------");
|
||||
|
||||
exception = (Throwable) meth.invoke(exception, (Object[]) null);
|
||||
try {
|
||||
exception.printStackTrace(s);
|
||||
// if exception is a TransformerException it will print
|
||||
// its contained exception, so we don't need to redo it here,
|
||||
// and we can exit the loop now.
|
||||
if (exception instanceof TransformerException) break;
|
||||
} catch (Throwable e) {
|
||||
s.println("Could not print stack trace...");
|
||||
}
|
||||
|
||||
if (prev == exception) {
|
||||
break;
|
||||
try {
|
||||
// Is this still needed?
|
||||
Method meth = exception.getClass().getMethod("getException");
|
||||
|
||||
if (null != meth) {
|
||||
Throwable prev = exception;
|
||||
|
||||
exception = (Throwable) meth.invoke(exception, (Object[]) null);
|
||||
|
||||
if (prev == exception) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
exception = null;
|
||||
}
|
||||
} else {
|
||||
} catch (InvocationTargetException ite) {
|
||||
exception = null;
|
||||
} catch (IllegalAccessException iae) {
|
||||
exception = null;
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
exception = null;
|
||||
}
|
||||
} catch (InvocationTargetException ite) {
|
||||
exception = null;
|
||||
} catch (IllegalAccessException iae) {
|
||||
exception = null;
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
exception = null;
|
||||
}
|
||||
} finally {
|
||||
// ensure output is written
|
||||
s.flush();
|
||||
}
|
||||
// insure output is written
|
||||
s.flush();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ package javax.xml.validation;
|
|||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
|
|
@ -41,13 +41,10 @@ class SecuritySupport {
|
|||
|
||||
ClassLoader getContextClassLoader() {
|
||||
return
|
||||
AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public ClassLoader run() {
|
||||
ClassLoader cl = null;
|
||||
//try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
//} catch (SecurityException ex) { }
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null)
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
return cl;
|
||||
|
@ -56,7 +53,7 @@ class SecuritySupport {
|
|||
}
|
||||
|
||||
String getSystemProperty(final String propName) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty(propName);
|
||||
|
@ -69,7 +66,7 @@ class SecuritySupport {
|
|||
{
|
||||
try {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<FileInputStream>() {
|
||||
new PrivilegedExceptionAction<>() {
|
||||
@Override
|
||||
public FileInputStream run() throws FileNotFoundException {
|
||||
return new FileInputStream(file);
|
||||
|
@ -82,7 +79,7 @@ class SecuritySupport {
|
|||
|
||||
// Used for debugging purposes
|
||||
String getClassSource(Class<?> cls) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public String run() {
|
||||
CodeSource cs = cls.getProtectionDomain().getCodeSource();
|
||||
|
@ -97,7 +94,7 @@ class SecuritySupport {
|
|||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
return f.exists();
|
||||
|
|
|
@ -40,7 +40,7 @@ class SecuritySupport {
|
|||
|
||||
|
||||
ClassLoader getContextClassLoader() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public ClassLoader run() {
|
||||
ClassLoader cl = null;
|
||||
|
@ -53,7 +53,7 @@ class SecuritySupport {
|
|||
}
|
||||
|
||||
String getSystemProperty(final String propName) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty(propName);
|
||||
|
@ -66,7 +66,7 @@ class SecuritySupport {
|
|||
{
|
||||
try {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<FileInputStream>() {
|
||||
new PrivilegedExceptionAction<>() {
|
||||
@Override
|
||||
public FileInputStream run() throws FileNotFoundException {
|
||||
return new FileInputStream(file);
|
||||
|
@ -79,7 +79,7 @@ class SecuritySupport {
|
|||
|
||||
// Used for debugging purposes
|
||||
String getClassSource(Class<?> cls) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public String run() {
|
||||
CodeSource cs = cls.getProtectionDomain().getCodeSource();
|
||||
|
@ -94,7 +94,7 @@ class SecuritySupport {
|
|||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
return f.exists();
|
||||
|
|
|
@ -28,7 +28,6 @@ package javax.xml.xpath;
|
|||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue