CPD Results
The following document contains the results of PMD's CPD 7.25.0.
Duplications
| File |
Line |
| org/apache/commons/logging/impl/ServletContextCleaner.java |
51 |
| org/apache/commons/logging/jakarta/ServletContextCleaner.java |
44 |
public class ServletContextCleaner implements ServletContextListener {
private static final Class<?>[] RELEASE_SIGNATURE = { ClassLoader.class };
/**
* Constructs a new instance.
*/
public ServletContextCleaner() {
// empty
}
/**
* Invoked when a webapp is undeployed, this tells the LogFactory
* class to release any logging information related to the current
* contextClassloader.
*/
@Override
public void contextDestroyed(final ServletContextEvent sce) {
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
final Object[] params = new Object[1];
params[0] = tccl;
// Walk up the tree of class loaders, finding all the available
// LogFactory classes and releasing any objects associated with
// the tccl (ie the webapp).
//
// When there is only one LogFactory in the classpath, and it
// is within the webapp being undeployed then there is no problem;
// garbage collection works fine.
//
// When there are multiple LogFactory classes in the classpath but
// parent-first classloading is used everywhere, this loop is really
// short. The first instance of LogFactory found will
// be the highest in the classpath, and then no more will be found.
// This is ok, as with this setup this will be the only LogFactory
// holding any data associated with the tccl being released.
//
// When there are multiple LogFactory classes in the classpath and
// child-first classloading is used in any class loader, then multiple
// LogFactory instances may hold info about this TCCL; whenever the
// webapp makes a call into a class loaded via an ancestor class loader
// and that class calls LogFactory the tccl gets registered in
// the LogFactory instance that is visible from the ancestor
// class loader. However the concrete logging library it points
// to is expected to have been loaded via the TCCL, so the
// underlying logging lib is only initialized/configured once.
// These references from ancestor LogFactory classes down to
// TCCL class loaders are held via weak references and so should
// be released but there are circumstances where they may not.
// Walking up the class loader ancestry ladder releasing
// the current tccl at each level tree, though, will definitely
// clear any problem references.
ClassLoader loader = tccl;
while (loader != null) {
// Load via the current loader. Note that if the class is not accessible
// via this loader, but is accessible via some ancestor then that class
// will be returned.
try {
@SuppressWarnings("unchecked")
final Class<LogFactory> logFactoryClass = (Class<LogFactory>) loader.loadClass("org.apache.commons.logging.LogFactory");
final Method releaseMethod = logFactoryClass.getMethod("release", RELEASE_SIGNATURE);
releaseMethod.invoke(null, params);
loader = logFactoryClass.getClassLoader().getParent();
} catch (final ClassNotFoundException ex) {
// Neither the current class loader nor any of its ancestors could find
// the LogFactory class, so we can stop now.
loader = null;
} catch (final NoSuchMethodException ex) {
// This is not expected; every version of JCL has this method
System.err.println("LogFactory instance found which does not support release method!");
loader = null;
} catch (final IllegalAccessException ex) {
// This is not expected; every ancestor class should be accessible
System.err.println("LogFactory instance found which is not accessible!");
loader = null;
} catch (final InvocationTargetException ex) {
// This is not expected
System.err.println("LogFactory instance release method failed!");
loader = null;
}
}
// Just to be sure, invoke release on the LogFactory that is visible from
// this ServletContextCleaner class too. This should already have been caught
// by the above loop but just in case...
LogFactory.release(tccl);
}
/**
* Invoked when a webapp is deployed. Nothing needs to be done here.
*/
@Override
public void contextInitialized(final ServletContextEvent sce) {
// do nothing
}
} |
| File |
Line |
| org/apache/commons/logging/impl/Jdk13LumberjackLogger.java |
184 |
| org/apache/commons/logging/impl/Jdk14Logger.java |
131 |
}
/**
* Gets the native Logger instance we are using.
*
* @return the native Logger instance we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(name);
}
return logger;
}
/**
* Logs a message with {@link java.util.logging.Level#INFO}.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
@Override
public void info(final Object message) {
log(Level.INFO, String.valueOf(message), null);
}
/**
* Logs a message with {@link java.util.logging.Level#INFO}.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
@Override
public void info(final Object message, final Throwable exception) {
log(Level.INFO, String.valueOf(message), exception);
}
/**
* Is debug logging currently enabled?
*/
@Override
public boolean isDebugEnabled() {
return getLogger().isLoggable(Level.FINE);
}
/**
* Is error logging currently enabled?
*/
@Override
public boolean isErrorEnabled() {
return getLogger().isLoggable(Level.SEVERE);
}
/**
* Is fatal logging currently enabled?
*/
@Override
public boolean isFatalEnabled() {
return getLogger().isLoggable(Level.SEVERE);
}
/**
* Is info logging currently enabled?
*/
@Override
public boolean isInfoEnabled() {
return getLogger().isLoggable(Level.INFO);
}
/**
* Is trace logging currently enabled?
*/
@Override
public boolean isTraceEnabled() {
return getLogger().isLoggable(Level.FINEST);
}
/**
* Is warn logging currently enabled?
*/
@Override
public boolean isWarnEnabled() {
return getLogger().isLoggable(Level.WARNING);
} |
| File |
Line |
| org/apache/commons/logging/impl/Jdk13LumberjackLogger.java |
79 |
| org/apache/commons/logging/impl/Jdk14Logger.java |
59 |
public Jdk13LumberjackLogger(final String name) {
this.name = name;
logger = getLogger();
}
/**
* Logs a message with {@link java.util.logging.Level#FINE}.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
@Override
public void debug(final Object message) {
log(Level.FINE, String.valueOf(message), null);
}
/**
* Logs a message with {@link java.util.logging.Level#FINE}.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
@Override
public void debug(final Object message, final Throwable exception) {
log(Level.FINE, String.valueOf(message), exception);
}
/**
* Logs a message with {@link java.util.logging.Level#SEVERE}.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
@Override
public void error(final Object message) {
log(Level.SEVERE, String.valueOf(message), null);
}
/**
* Logs a message with {@link java.util.logging.Level#SEVERE}.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
@Override
public void error(final Object message, final Throwable exception) {
log(Level.SEVERE, String.valueOf(message), exception);
}
/**
* Logs a message with {@link java.util.logging.Level#SEVERE}.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
@Override
public void fatal(final Object message) {
log(Level.SEVERE, String.valueOf(message), null);
}
/**
* Logs a message with {@link java.util.logging.Level#SEVERE}.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
@Override
public void fatal(final Object message, final Throwable exception) {
log(Level.SEVERE, String.valueOf(message), exception);
} |
| File |
Line |
| org/apache/commons/logging/impl/AvalonLogger.java |
208 |
| org/apache/commons/logging/impl/LogKitLogger.java |
182 |
if (getLogger().isInfoEnabled()) {
getLogger().info(String.valueOf(message), t);
}
}
/**
* Is logging to {@code org.apache.avalon.framework.logger.Logger.debug} enabled?
*
* @see org.apache.commons.logging.Log#isDebugEnabled()
*/
@Override
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Is logging to {@code org.apache.avalon.framework.logger.Logger.error} enabled?
*
* @see org.apache.commons.logging.Log#isErrorEnabled()
*/
@Override
public boolean isErrorEnabled() {
return getLogger().isErrorEnabled();
}
/**
* Is logging to {@code org.apache.avalon.framework.logger.Logger.fatalError} enabled?
*
* @see org.apache.commons.logging.Log#isFatalEnabled()
*/
@Override
public boolean isFatalEnabled() {
return getLogger().isFatalErrorEnabled();
}
/**
* Is logging to {@code org.apache.avalon.framework.logger.Logger.info} enabled?
*
* @see org.apache.commons.logging.Log#isInfoEnabled()
*/
@Override
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
/**
* Is logging to {@code org.apache.avalon.framework.logger.Logger.debug} enabled?
*
* @see org.apache.commons.logging.Log#isTraceEnabled()
*/
@Override
public boolean isTraceEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Is logging to {@code org.apache.avalon.framework.logger.Logger.warn} enabled?
*
* @see org.apache.commons.logging.Log#isWarnEnabled()
*/
@Override
public boolean isWarnEnabled() {
return getLogger().isWarnEnabled();
}
/**
* Logs a message with {@code org.apache.avalon.framework.logger.Logger.debug}.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
@Override
public void trace(final Object message) { |
| File |
Line |
| org/apache/commons/logging/impl/Jdk13LumberjackLogger.java |
281 |
| org/apache/commons/logging/impl/Jdk14Logger.java |
242 |
}
}
/**
* Logs a message with {@link java.util.logging.Level#FINEST}.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
@Override
public void trace(final Object message) {
log(Level.FINEST, String.valueOf(message), null);
}
/**
* Logs a message with {@link java.util.logging.Level#FINEST}.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
@Override
public void trace(final Object message, final Throwable exception) {
log(Level.FINEST, String.valueOf(message), exception);
}
/**
* Logs a message with {@link java.util.logging.Level#WARNING}.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
@Override
public void warn(final Object message) {
log(Level.WARNING, String.valueOf(message), null);
}
/**
* Logs a message with {@link java.util.logging.Level#WARNING}.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
@Override
public void warn(final Object message, final Throwable exception) {
log(Level.WARNING, String.valueOf(message), exception);
}
} |
|