No need to nest in else.
This commit is contained in:
@@ -878,9 +878,8 @@ public abstract class LogFactory {
|
|||||||
//
|
//
|
||||||
// nb: nullClassLoaderFactory might be null. That's ok.
|
// nb: nullClassLoaderFactory might be null. That's ok.
|
||||||
return nullClassLoaderFactory;
|
return nullClassLoaderFactory;
|
||||||
} else {
|
|
||||||
return (LogFactory) factories.get(contextClassLoader);
|
|
||||||
}
|
}
|
||||||
|
return (LogFactory) factories.get(contextClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1239,9 +1238,8 @@ public abstract class LogFactory {
|
|||||||
public Object run() {
|
public Object run() {
|
||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
return loader.getResourceAsStream(name);
|
return loader.getResourceAsStream(name);
|
||||||
} else {
|
|
||||||
return ClassLoader.getSystemResourceAsStream(name);
|
|
||||||
}
|
}
|
||||||
|
return ClassLoader.getSystemResourceAsStream(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1267,9 +1265,8 @@ public abstract class LogFactory {
|
|||||||
try {
|
try {
|
||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
return loader.getResources(name);
|
return loader.getResources(name);
|
||||||
} else {
|
|
||||||
return ClassLoader.getSystemResources(name);
|
|
||||||
}
|
}
|
||||||
|
return ClassLoader.getSystemResources(name);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Exception while trying to find configuration file " +
|
logDiagnostic("Exception while trying to find configuration file " +
|
||||||
@@ -1475,9 +1472,10 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
if (dest.equals("STDOUT")) {
|
if (dest.equals("STDOUT")) {
|
||||||
return System.out;
|
return System.out;
|
||||||
} else if (dest.equals("STDERR")) {
|
}
|
||||||
|
if (dest.equals("STDERR")) {
|
||||||
return System.err;
|
return System.err;
|
||||||
} else {
|
}
|
||||||
try {
|
try {
|
||||||
// open the file in append mode
|
// open the file in append mode
|
||||||
final FileOutputStream fos = new FileOutputStream(dest, true);
|
final FileOutputStream fos = new FileOutputStream(dest, true);
|
||||||
@@ -1487,7 +1485,6 @@ public abstract class LogFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates true if the user has enabled internal logging.
|
* Indicates true if the user has enabled internal logging.
|
||||||
@@ -1651,9 +1648,8 @@ public abstract class LogFactory {
|
|||||||
public static String objectId(final Object o) {
|
public static String objectId(final Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return "null";
|
return "null";
|
||||||
} else {
|
|
||||||
return o.getClass().getName() + "@" + System.identityHashCode(o);
|
|
||||||
}
|
}
|
||||||
|
return o.getClass().getName() + "@" + System.identityHashCode(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -682,12 +682,11 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
logDiagnostic("Did not find '" + name + "'.");
|
logDiagnostic("Did not find '" + name + "'.");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Found '" + name + "'.");
|
logDiagnostic("Found '" + name + "'.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
} catch (final LogConfigurationException e) {
|
} catch (final LogConfigurationException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Logging system '" + name + "' is available but not useable.");
|
logDiagnostic("Logging system '" + name + "' is available but not useable.");
|
||||||
@@ -1166,7 +1165,11 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// In some classloading setups (e.g. JBoss with its
|
// In some classloading setups (e.g. JBoss with its
|
||||||
// UnifiedLoaderRepository) this can still work, so if user hasn't
|
// UnifiedLoaderRepository) this can still work, so if user hasn't
|
||||||
// forbidden it, just return the contextClassLoader.
|
// forbidden it, just return the contextClassLoader.
|
||||||
if (allowFlawedContext) {
|
if (!allowFlawedContext) {
|
||||||
|
throw new LogConfigurationException("Bad classloader hierarchy; LogFactoryImpl was loaded via" +
|
||||||
|
" a classloader that is not related to the current context" +
|
||||||
|
" classloader.");
|
||||||
|
}
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[WARNING] the context classloader is not part of a" +
|
logDiagnostic("[WARNING] the context classloader is not part of a" +
|
||||||
" parent-child relationship with the classloader that" +
|
" parent-child relationship with the classloader that" +
|
||||||
@@ -1177,12 +1180,6 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// contextClassLoader is not null, so we can just return it.
|
// contextClassLoader is not null, so we can just return it.
|
||||||
return contextClassLoader;
|
return contextClassLoader;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
throw new LogConfigurationException("Bad classloader hierarchy; LogFactoryImpl was loaded via" +
|
|
||||||
" a classloader that is not related to the current context" +
|
|
||||||
" classloader.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseClassLoader != contextClassLoader) {
|
if (baseClassLoader != contextClassLoader) {
|
||||||
// We really should just use the contextClassLoader as the starting
|
// We really should just use the contextClassLoader as the starting
|
||||||
@@ -1190,7 +1187,12 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// that there are a number of broken systems out there which create
|
// that there are a number of broken systems out there which create
|
||||||
// custom classloaders but fail to set the context classloader so
|
// custom classloaders but fail to set the context classloader so
|
||||||
// we handle those flawed systems anyway.
|
// we handle those flawed systems anyway.
|
||||||
if (allowFlawedContext) {
|
if (!allowFlawedContext) {
|
||||||
|
throw new LogConfigurationException(
|
||||||
|
"Bad classloader hierarchy; LogFactoryImpl was loaded via" +
|
||||||
|
" a classloader that is not related to the current context" +
|
||||||
|
" classloader.");
|
||||||
|
}
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic(
|
logDiagnostic(
|
||||||
"Warning: the context classloader is an ancestor of the" +
|
"Warning: the context classloader is an ancestor of the" +
|
||||||
@@ -1199,12 +1201,6 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
" commons-logging should ensure the context classloader" +
|
" commons-logging should ensure the context classloader" +
|
||||||
" is used correctly.");
|
" is used correctly.");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new LogConfigurationException(
|
|
||||||
"Bad classloader hierarchy; LogFactoryImpl was loaded via" +
|
|
||||||
" a classloader that is not related to the current context" +
|
|
||||||
" classloader.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseClassLoader;
|
return baseClassLoader;
|
||||||
|
|||||||
@@ -633,9 +633,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* obtain a class loader) will trigger this exception where
|
* obtain a class loader) will trigger this exception where
|
||||||
* we can make a distinction.
|
* we can make a distinction.
|
||||||
*/
|
*/
|
||||||
if (e.getTargetException() instanceof SecurityException) {
|
if (!(e.getTargetException() instanceof SecurityException)) {
|
||||||
// ignore
|
|
||||||
} else {
|
|
||||||
// Capture 'e.getTargetException()' exception for details
|
// Capture 'e.getTargetException()' exception for details
|
||||||
// alternate: log 'e.getTargetException()', and pass back 'e'.
|
// alternate: log 'e.getTargetException()', and pass back 'e'.
|
||||||
throw new LogConfigurationException
|
throw new LogConfigurationException
|
||||||
@@ -664,9 +662,8 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
|
|
||||||
if (threadCL != null) {
|
if (threadCL != null) {
|
||||||
return threadCL.getResourceAsStream(name);
|
return threadCL.getResourceAsStream(name);
|
||||||
} else {
|
|
||||||
return ClassLoader.getSystemResourceAsStream(name);
|
|
||||||
}
|
}
|
||||||
|
return ClassLoader.getSystemResourceAsStream(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -312,14 +312,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
|
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.loadClass(name, resolve);
|
return super.loadClass(name, resolve);
|
||||||
} else {
|
}
|
||||||
// Implement child-first.
|
|
||||||
//
|
|
||||||
// It appears that the findClass method doesn't check whether the
|
|
||||||
// class has already been loaded. This seems odd to me, but without
|
|
||||||
// first checking via findLoadedClass we can get java.lang.LinkageError
|
|
||||||
// with message "duplicate class definition" which isn't good.
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class clazz = findLoadedClass(name);
|
Class clazz = findLoadedClass(name);
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
@@ -333,7 +326,6 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
return super.loadClass(name, resolve);
|
return super.loadClass(name, resolve);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as parent class method except that when parentFirst is false
|
* Same as parent class method except that when parentFirst is false
|
||||||
@@ -344,14 +336,13 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
public URL getResource(final String name) {
|
public URL getResource(final String name) {
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResource(name);
|
return super.getResource(name);
|
||||||
} else {
|
}
|
||||||
final URL local = super.findResource(name);
|
final URL local = super.findResource(name);
|
||||||
if (local != null) {
|
if (local != null) {
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
return super.getResource(name);
|
return super.getResource(name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emulate a proper implementation of getResources which respects the
|
* Emulate a proper implementation of getResources which respects the
|
||||||
@@ -364,7 +355,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
public Enumeration getResourcesInOrder(final String name) throws IOException {
|
public Enumeration getResourcesInOrder(final String name) throws IOException {
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResources(name);
|
return super.getResources(name);
|
||||||
} else {
|
}
|
||||||
final Enumeration localUrls = super.findResources(name);
|
final Enumeration localUrls = super.findResources(name);
|
||||||
|
|
||||||
final ClassLoader parent = getParent();
|
final ClassLoader parent = getParent();
|
||||||
@@ -388,7 +379,6 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
localItems.addAll(parentItems);
|
localItems.addAll(parentItems);
|
||||||
return Collections.enumeration(localItems);
|
return Collections.enumeration(localItems);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -418,7 +408,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
public InputStream getResourceAsStream(final String name) {
|
public InputStream getResourceAsStream(final String name) {
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResourceAsStream(name);
|
return super.getResourceAsStream(name);
|
||||||
} else {
|
}
|
||||||
final URL local = super.findResource(name);
|
final URL local = super.findResource(name);
|
||||||
if (local != null) {
|
if (local != null) {
|
||||||
try {
|
try {
|
||||||
@@ -431,5 +421,4 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
return super.getResourceAsStream(name);
|
return super.getResourceAsStream(name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,12 +251,11 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
if(weakHashtable.get(new Long(1)) == null) {
|
if(weakHashtable.get(new Long(1)) == null) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else {
|
}
|
||||||
// create garbage:
|
// create garbage:
|
||||||
final byte[] b = new byte[bytz];
|
final byte[] b = new byte[bytz];
|
||||||
bytz = bytz * 2;
|
bytz = bytz * 2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// some JVMs seem to take a little time to put references on
|
// some JVMs seem to take a little time to put references on
|
||||||
// the reference queue once the reference has been collected
|
// the reference queue once the reference has been collected
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
// the call stack.
|
// the call stack.
|
||||||
System.out.println("Access controller found: returning");
|
System.out.println("Access controller found: returning");
|
||||||
return;
|
return;
|
||||||
} else if (cname.startsWith("java.")
|
}
|
||||||
|
if (cname.startsWith("java.")
|
||||||
|| cname.startsWith("javax.")
|
|| cname.startsWith("javax.")
|
||||||
|| cname.startsWith("junit.")
|
|| cname.startsWith("junit.")
|
||||||
|| cname.startsWith("org.apache.tools.ant.")
|
|| cname.startsWith("org.apache.tools.ant.")
|
||||||
@@ -133,13 +134,12 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
System.out.println("Untrusted code [testcase] found");
|
System.out.println("Untrusted code [testcase] found");
|
||||||
throw new SecurityException("Untrusted code [testcase] found");
|
throw new SecurityException("Untrusted code [testcase] found");
|
||||||
} else if (cname.startsWith("org.apache.commons.logging.")) {
|
} else if (cname.startsWith("org.apache.commons.logging.")) {
|
||||||
if (permissions.implies(p)) {
|
if (!permissions.implies(p)) {
|
||||||
// Code here is trusted if the caller is trusted
|
|
||||||
System.out.println("Permission in allowed set for JCL class");
|
|
||||||
} else {
|
|
||||||
System.out.println("Permission refused:" + p.getClass() + ":" + p);
|
System.out.println("Permission refused:" + p.getClass() + ":" + p);
|
||||||
throw new SecurityException("Permission refused:" + p.getClass() + ":" + p);
|
throw new SecurityException("Permission refused:" + p.getClass() + ":" + p);
|
||||||
}
|
}
|
||||||
|
// Code here is trusted if the caller is trusted
|
||||||
|
System.out.println("Permission in allowed set for JCL class");
|
||||||
} else {
|
} else {
|
||||||
// we found some code that is not trusted to perform this operation.
|
// we found some code that is not trusted to perform this operation.
|
||||||
System.out.println("Unexpected code: permission refused:" + p.getClass() + ":" + p);
|
System.out.println("Unexpected code: permission refused:" + p.getClass() + ":" + p);
|
||||||
|
|||||||
Reference in New Issue
Block a user