1
0

Fix Javadoc warnings and errors

This commit is contained in:
Gary Gregory
2023-10-10 15:22:39 -04:00
parent 75a09ea648
commit 42ad2ae0b6
10 changed files with 278 additions and 212 deletions

View File

@@ -204,42 +204,37 @@ public abstract class LogFactory {
* or {@code null} if there is no such attribute. * or {@code null} if there is no such attribute.
* *
* @param name Name of the attribute to return * @param name Name of the attribute to return
* @return the configuration attribute with the specified name.
*/ */
public abstract Object getAttribute(String name); public abstract Object getAttribute(String name);
/** /**
* Return an array containing the names of all currently defined * Gets an array containing the names of all currently defined configuration attributes. If there are no such attributes, a zero length array is returned.
* configuration attributes. If there are no such attributes, a zero *
* length array is returned. * @return an array containing the names of all currently defined configuration attributes
*/ */
public abstract String[] getAttributeNames(); public abstract String[] getAttributeNames();
/** /**
* Convenience method to derive a name from the specified class and * Convenience method to derive a name from the specified class and call {@code getInstance(String)} with it.
* call {@code getInstance(String)} with it.
* *
* @param clazz Class for which a suitable Log name will be derived * @param clazz Class for which a suitable Log name will be derived
* @throws LogConfigurationException if a suitable {@code Log} * @return a name from the specified class.
* instance cannot be returned * @throws LogConfigurationException if a suitable {@code Log} instance cannot be returned
*/ */
public abstract Log getInstance(Class clazz) public abstract Log getInstance(Class clazz) throws LogConfigurationException;
throws LogConfigurationException;
/** /**
* Construct (if necessary) and return a {@code Log} instance, * Construct (if necessary) and return a {@code Log} instance, using the factory's current set of configuration attributes.
* using the factory's current set of configuration attributes.
* <p> * <p>
* <strong>NOTE</strong> - Depending upon the implementation of * <strong>NOTE</strong> - Depending upon the implementation of the {@code LogFactory} you are using, the {@code Log} instance you are returned may or may
* the {@code LogFactory} you are using, the {@code Log} * not be local to the current application, and may or may not be returned again on a subsequent call with the same name argument.
* instance you are returned may or may not be local to the current * </p>
* application, and may or may not be returned again on a subsequent
* call with the same name argument.
* *
* @param name Logical name of the {@code Log} instance to be * @param name Logical name of the {@code Log} instance to be returned (the meaning of this name is only known to the underlying logging implementation that
* returned (the meaning of this name is only known to the underlying * is being wrapped)
* logging implementation that is being wrapped) * @return a {@code Log} instance.
* @throws LogConfigurationException if a suitable {@code Log} * @throws LogConfigurationException if a suitable {@code Log} instance cannot be returned
* instance cannot be returned
*/ */
public abstract Log getInstance(String name) public abstract Log getInstance(String name)
throws LogConfigurationException; throws LogConfigurationException;
@@ -385,34 +380,26 @@ public abstract class LogFactory {
} }
/** /**
* Construct (if necessary) and return a {@code LogFactory} * Construct (if necessary) and return a {@code LogFactory} instance, using the following ordered lookup procedure to determine the name of the
* instance, using the following ordered lookup procedure to determine * implementation class to be loaded.
* the name of the implementation class to be loaded.
* <p>
* <ul> * <ul>
* <li>The {@code org.apache.commons.logging.LogFactory} system * <li>The {@code org.apache.commons.logging.LogFactory} system property.</li>
* property.</li>
* <li>The JDK 1.3 Service Discovery mechanism</li> * <li>The JDK 1.3 Service Discovery mechanism</li>
* <li>Use the properties file {@code commons-logging.properties} * <li>Use the properties file {@code commons-logging.properties} file, if found in the class path of this class. The configuration file is in standard
* file, if found in the class path of this class. The configuration * {@code java.util.Properties} format and contains the fully qualified name of the implementation class with the key being the system property defined
* file is in standard {@code java.util.Properties} format and * above.</li>
* contains the fully qualified name of the implementation class * <li>Fall back to a default implementation class ({@code org.apache.commons.logging.impl.LogFactoryImpl}).</li>
* with the key being the system property defined above.</li>
* <li>Fall back to a default implementation class
* ({@code org.apache.commons.logging.impl.LogFactoryImpl}).</li>
* </ul> * </ul>
* <p> * <p>
* <em>NOTE</em> - If the properties file method of identifying the * <em>NOTE</em> - If the properties file method of identifying the {@code LogFactory} implementation class is utilized, all of the properties defined in
* {@code LogFactory} implementation class is utilized, all of the * this file will be set as configuration attributes on the corresponding {@code LogFactory} instance.
* properties defined in this file will be set as configuration attributes * </p>
* on the corresponding {@code LogFactory} instance.
* <p> * <p>
* <em>NOTE</em> - In a multi-threaded environment it is possible * <em>NOTE</em> - In a multi-threaded environment it is possible that two different instances will be returned for the same classloader environment.
* that two different instances will be returned for the same * </p>
* classloader environment.
* *
* @throws LogConfigurationException if the implementation class is not * @return a {@code LogFactory}.
* available or cannot be instantiated. * @throws LogConfigurationException if the implementation class is not available or cannot be instantiated.
*/ */
public static LogFactory getFactory() throws LogConfigurationException { public static LogFactory getFactory() throws LogConfigurationException {
// Identify the class loader we will be using // Identify the class loader we will be using
@@ -645,26 +632,23 @@ public abstract class LogFactory {
} }
/** /**
* Convenience method to return a named logger, without the application * Convenience method to return a named logger, without the application having to care about factories.
* having to care about factories.
* *
* @param clazz Class from which a log name will be derived * @param clazz Class from which a log name will be derived
* @throws LogConfigurationException if a suitable {@code Log} * @return a named logger.
* instance cannot be returned * @throws LogConfigurationException if a suitable {@code Log} instance cannot be returned
*/ */
public static Log getLog(final Class clazz) throws LogConfigurationException { public static Log getLog(final Class clazz) throws LogConfigurationException {
return getFactory().getInstance(clazz); return getFactory().getInstance(clazz);
} }
/** /**
* Convenience method to return a named logger, without the application * Convenience method to return a named logger, without the application having to care about factories.
* having to care about factories.
* *
* @param name Logical name of the {@code Log} instance to be * @param name Logical name of the {@code Log} instance to be returned (the meaning of this name is only known to the underlying logging implementation that
* returned (the meaning of this name is only known to the underlying * is being wrapped)
* logging implementation that is being wrapped) * @return a named logger.
* @throws LogConfigurationException if a suitable {@code Log} * @throws LogConfigurationException if a suitable {@code Log} instance cannot be returned
* instance cannot be returned
*/ */
public static Log getLog(final String name) throws LogConfigurationException { public static Log getLog(final String name) throws LogConfigurationException {
return getFactory().getInstance(name); return getFactory().getInstance(name);
@@ -741,6 +725,7 @@ public abstract class LogFactory {
* all code is written to call this method rather than Class.getClassLoader, * all code is written to call this method rather than Class.getClassLoader,
* so that we could put AccessController stuff in this method without any * so that we could put AccessController stuff in this method without any
* disruption later if we need to. * disruption later if we need to.
* </p>
* <p> * <p>
* Even when using an AccessController, however, this method can still * Even when using an AccessController, however, this method can still
* throw SecurityException. Commons-logging basically relies on the * throw SecurityException. Commons-logging basically relies on the
@@ -750,11 +735,16 @@ public abstract class LogFactory {
* from starting up. Maybe it would be good to detect this situation and * from starting up. Maybe it would be good to detect this situation and
* just disable all commons-logging? Not high priority though - as stated * just disable all commons-logging? Not high priority though - as stated
* above, security policies that prevent classloader access aren't common. * above, security policies that prevent classloader access aren't common.
* </p>
* <p> * <p>
* Note that returning an object fetched via an AccessController would * Note that returning an object fetched via an AccessController would
* technically be a security flaw anyway; untrusted code that has access * technically be a security flaw anyway; untrusted code that has access
* to a trusted JCL library could use it to fetch the classloader for * to a trusted JCL library could use it to fetch the classloader for
* a class even when forbidden to do so directly. * a class even when forbidden to do so directly.
* </p>
*
* @param clazz Class.
* @return a ClassLoader.
* *
* @since 1.1 * @since 1.1
*/ */
@@ -905,47 +895,35 @@ public abstract class LogFactory {
} }
/** /**
* Return a new instance of the specified {@code LogFactory} * Return a new instance of the specified {@code LogFactory} implementation class, loaded by the specified class loader. If that fails, try the class loader
* implementation class, loaded by the specified class loader. * used to load this (abstract) LogFactory.
* If that fails, try the class loader used to load this * <h4>ClassLoader conflicts</h4>
* (abstract) LogFactory.
* <h2>ClassLoader conflicts</h2>
* <p> * <p>
* Note that there can be problems if the specified ClassLoader is not the * Note that there can be problems if the specified ClassLoader is not the same as the classloader that loaded this class, ie when loading a concrete
* same as the classloader that loaded this class, ie when loading a * LogFactory subclass via a context classloader.
* concrete LogFactory subclass via a context classloader. * </p>
* <p> * <p>
* The problem is the same one that can occur when loading a concrete Log * The problem is the same one that can occur when loading a concrete Log subclass via a context classloader.
* subclass via a context classloader. * </p>
* <p> * <p>
* The problem occurs when code running in the context classloader calls * The problem occurs when code running in the context classloader calls class X which was loaded via a parent classloader, and class X then calls
* class X which was loaded via a parent classloader, and class X then calls * LogFactory.getFactory (either directly or via LogFactory.getLog). Because class X was loaded via the parent, it binds to LogFactory loaded via the
* LogFactory.getFactory (either directly or via LogFactory.getLog). Because * parent. When the code in this method finds some LogFactoryYYYY class in the child (context) classloader, and there also happens to be a LogFactory class
* class X was loaded via the parent, it binds to LogFactory loaded via * defined in the child classloader, then LogFactoryYYYY will be bound to LogFactory@childloader. It cannot be cast to LogFactory@parentloader, ie this
* the parent. When the code in this method finds some LogFactoryYYYY * method cannot return the object as the desired type. Note that it doesn't matter if the LogFactory class in the child classloader is identical to the
* class in the child (context) classloader, and there also happens to be a * LogFactory class in the parent classloader, they are not compatible.
* LogFactory class defined in the child classloader, then LogFactoryYYYY * </p>
* will be bound to LogFactory@childloader. It cannot be cast to
* LogFactory@parentloader, ie this method cannot return the object as
* the desired type. Note that it doesn't matter if the LogFactory class
* in the child classloader is identical to the LogFactory class in the
* parent classloader, they are not compatible.
* <p> * <p>
* The solution taken here is to simply print out an error message when * The solution taken here is to simply print out an error message when this occurs then throw an exception. The deployer of the application must ensure
* this occurs then throw an exception. The deployer of the application * they remove all occurrences of the LogFactory class from the child classloader in order to resolve the issue. Note that they do not have to move the
* must ensure they remove all occurrences of the LogFactory class from * custom LogFactory subclass; that is ok as long as the only LogFactory class it can find to bind to is in the parent classloader.
* the child classloader in order to resolve the issue. Note that they * </p>
* do not have to move the custom LogFactory subclass; that is ok as
* long as the only LogFactory class it can find to bind to is in the
* parent classloader.
* *
* @param factoryClass Fully qualified name of the {@code LogFactory} * @param factoryClass Fully qualified name of the {@code LogFactory} implementation class
* implementation class
* @param classLoader ClassLoader from which to load this class * @param classLoader ClassLoader from which to load this class
* @param contextClassLoader is the context that this new factory will * @param contextClassLoader is the context that this new factory will manage logging for.
* manage logging for. * @return a new instance of the specified {@code LogFactory}.
* @throws LogConfigurationException if a suitable instance * @throws LogConfigurationException if a suitable instance cannot be created
* cannot be created
* @since 1.1 * @since 1.1
*/ */
protected static LogFactory newFactory(final String factoryClass, protected static LogFactory newFactory(final String factoryClass,
@@ -991,6 +969,11 @@ public abstract class LogFactory {
* directly via CustomFactoryImpl.getFactory or similar would ever call * directly via CustomFactoryImpl.getFactory or similar would ever call
* this. Anyway, it's here just in case, though the "managed class loader" * this. Anyway, it's here just in case, though the "managed class loader"
* value output to the diagnostics will not report the correct value. * value output to the diagnostics will not report the correct value.
* </p>
*
* @param factoryClass factory class.
* @param classLoader class loader.
* @return a LogFactory.
*/ */
protected static LogFactory newFactory(final String factoryClass, protected static LogFactory newFactory(final String factoryClass,
final ClassLoader classLoader) { final ClassLoader classLoader) {
@@ -1000,11 +983,9 @@ public abstract class LogFactory {
/** /**
* Implements the operations described in the javadoc for newFactory. * Implements the operations described in the javadoc for newFactory.
* *
* @param factoryClass * @param factoryClass Factory class.
* @param classLoader used to load the specified factory class. This is * @param classLoader used to load the specified factory class. This is expected to be either the TCCL or the classloader which loaded this class. Note
* expected to be either the TCCL or the classloader which loaded this * that the classloader which loaded this class might be "null" (ie the bootloader) for embedded systems.
* class. Note that the classloader which loaded this class might be
* "null" (ie the bootloader) for embedded systems.
* @return either a LogFactory object or a LogConfigurationException object. * @return either a LogFactory object or a LogConfigurationException object.
* @since 1.1 * @since 1.1
*/ */

View File

@@ -55,6 +55,9 @@ public class LogSource {
// ------------------------------------------------------- Class Attributes // ------------------------------------------------------- Class Attributes
/**
* Logs.
*/
static protected Hashtable logs = new Hashtable(); static protected Hashtable logs = new Hashtable();
/** Is log4j available (in the current classpath) */ /** Is log4j available (in the current classpath) */
@@ -138,15 +141,21 @@ public class LogSource {
// ---------------------------------------------------------- Class Methods // ---------------------------------------------------------- Class Methods
/** /**
* Set the log implementation/log implementation factory * Set the log implementation/log implementation factory by the name of the class. The given class must implement {@link Log}, and provide a constructor
* by the name of the class. The given class must implement {@link Log}, * that takes a single {@link String} argument (containing the name of the log).
* and provide a constructor that takes a single {@link String} argument *
* (containing the name of the log). * @param className class name.
* @throws LinkageError if there is missing dependency.
* @throws NoSuchMethodException if a matching method is not found.
* @throws SecurityException If a security manager, <i>s</i>, is present and the caller's class loader is not the same as or an ancestor of the class
* loader for the current class and invocation of {@link SecurityManager#checkPackageAccess s.checkPackageAccess()} denies
* access to the package of this class.
* @throws ClassNotFoundException if the class cannot be located
*/ */
static public void setLogImplementation(final String classname) static public void setLogImplementation(final String className)
throws LinkageError, NoSuchMethodException, SecurityException, ClassNotFoundException { throws LinkageError, NoSuchMethodException, SecurityException, ClassNotFoundException {
try { try {
final Class logclass = Class.forName(classname); final Class logclass = Class.forName(className);
final Class[] argtypes = new Class[1]; final Class[] argtypes = new Class[1];
argtypes[0] = "".getClass(); argtypes[0] = "".getClass();
logImplctor = logclass.getConstructor(argtypes); logImplctor = logclass.getConstructor(argtypes);
@@ -156,9 +165,16 @@ public class LogSource {
} }
/** /**
* Set the log implementation/log implementation factory by class. * Set the log implementation/log implementation factory by class. The given class must implement {@link Log}, and provide a constructor that takes a single
* The given class must implement {@link Log}, and provide a constructor * {@link String} argument (containing the name of the log).
* that takes a single {@link String} argument (containing the name of the log). *
* @param logclass class.
* @throws LinkageError if there is missing dependency.
* @throws ExceptionInInitializerError unexpected exception has occurred in a static initializer.
* @throws NoSuchMethodException if a matching method is not found.
* @throws SecurityException If a security manager, <i>s</i>, is present and the caller's class loader is not the same as or an ancestor of the
* class loader for the current class and invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package of this class.
*/ */
static public void setLogImplementation(final Class logclass) static public void setLogImplementation(final Class logclass)
throws LinkageError, ExceptionInInitializerError, NoSuchMethodException, SecurityException { throws LinkageError, ExceptionInInitializerError, NoSuchMethodException, SecurityException {
@@ -167,12 +183,22 @@ public class LogSource {
logImplctor = logclass.getConstructor(argtypes); logImplctor = logclass.getConstructor(argtypes);
} }
/** Get a {@code Log} instance by class name. */ /**
* Get a {@code Log} instance by class name.
*
* @param name Class name.
* @return a {@code Log} instance.
*/
static public Log getInstance(final String name) { static public Log getInstance(final String name) {
return (Log) logs.computeIfAbsent(name, k -> makeNewLogInstance(name)); return (Log) logs.computeIfAbsent(name, k -> makeNewLogInstance(name));
} }
/** Get a {@code Log} instance by class. */ /**
* Get a {@code Log} instance by class.
*
* @param clazz a Class.
* @return a {@code Log} instance.
*/
static public Log getInstance(final Class clazz) { static public Log getInstance(final Class clazz) {
return getInstance(clazz.getName()); return getInstance(clazz.getName());
} }
@@ -193,6 +219,7 @@ public class LogSource {
* are on a JDK 1.4 or later system, or NoOpLog if neither of the above conditions is true. * are on a JDK 1.4 or later system, or NoOpLog if neither of the above conditions is true.
* *
* @param name the log name (or category) * @param name the log name (or category)
* @return a new instance.
*/ */
static public Log makeNewLogInstance(final String name) { static public Log makeNewLogInstance(final String name) {
Log log; Log log;
@@ -211,6 +238,9 @@ public class LogSource {
/** /**
* Returns a {@link String} array containing the names of * Returns a {@link String} array containing the names of
* all logs known to me. * all logs known to me.
*
* @return a {@link String} array containing the names of
* all logs known to me.
*/ */
static public String[] getLogNames() { static public String[] getLogNames() {
return (String[]) logs.keySet().toArray(EMPTY_STRING_ARRAY); return (String[]) logs.keySet().toArray(EMPTY_STRING_ARRAY);

View File

@@ -47,9 +47,19 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
* The underlying Logger implementation we are using. * The underlying Logger implementation we are using.
*/ */
protected transient Logger logger; protected transient Logger logger;
/**
* Name.
*/
protected String name; protected String name;
/** Source class name. */
private String sourceClassName = "unknown"; private String sourceClassName = "unknown";
/** Source method name. */
private String sourceMethodName = "unknown"; private String sourceMethodName = "unknown";
/** Class and method found flag. */
private boolean classAndMethodFound; private boolean classAndMethodFound;
/** /**
@@ -194,6 +204,8 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
/** /**
* Return the native Logger instance we are using. * Return the native Logger instance we are using.
*
* @return the native Logger instance we are using.
*/ */
public Logger getLogger() { public Logger getLogger() {
if (logger == null) { if (logger == null) {

View File

@@ -53,8 +53,6 @@ public class Jdk14Logger implements Log, Serializable {
logger = getLogger(); logger = getLogger();
} }
// ----------------------------------------------------- Instance Variables
/** /**
* The underlying Logger implementation we are using. * The underlying Logger implementation we are using.
*/ */
@@ -65,9 +63,13 @@ public class Jdk14Logger implements Log, Serializable {
*/ */
protected String name; protected String name;
// --------------------------------------------------------- Protected Methods /**
* Logs a message at the given level.
protected void log( final Level level, final String msg, final Throwable ex ) { * @param level The level.
* @param msg The message.
* @param ex The exception.
*/
protected void log(final Level level, final String msg, final Throwable ex) {
final Logger logger = getLogger(); final Logger logger = getLogger();
if (logger.isLoggable(level)) { if (logger.isLoggable(level)) {
// Hack (?) to get the stack trace. // Hack (?) to get the stack trace.
@@ -77,20 +79,18 @@ public class Jdk14Logger implements Log, Serializable {
final String cname = name; final String cname = name;
String method = "unknown"; String method = "unknown";
// Caller will be the third element // Caller will be the third element
if ( locations != null && locations.length > 2 ) { if (locations != null && locations.length > 2) {
final StackTraceElement caller = locations[2]; final StackTraceElement caller = locations[2];
method = caller.getMethodName(); method = caller.getMethodName();
} }
if ( ex == null ) { if (ex == null) {
logger.logp( level, cname, method, msg ); logger.logp(level, cname, method, msg);
} else { } else {
logger.logp( level, cname, method, msg, ex ); logger.logp(level, cname, method, msg, ex);
} }
} }
} }
// --------------------------------------------------------- Public Methods
/** /**
* Logs a message with {@code java.util.logging.Level.FINE}. * Logs a message with {@code java.util.logging.Level.FINE}.
* *
@@ -162,6 +162,8 @@ public class Jdk14Logger implements Log, Serializable {
/** /**
* Return the native Logger instance we are using. * Return the native Logger instance we are using.
*
* @return the native Logger instance we are using.
*/ */
public Logger getLogger() { public Logger getLogger() {
if (logger == null) { if (logger == null) {

View File

@@ -90,14 +90,17 @@ public class Log4JLogger implements Log, Serializable {
traceLevel = _traceLevel; traceLevel = _traceLevel;
} }
// ------------------------------------------------------------ Constructor /**
* Constructs a new instance.
*/
public Log4JLogger() { public Log4JLogger() {
name = null; name = null;
} }
/** /**
* Base constructor. * Base constructor.
*
* @param name name.
*/ */
public Log4JLogger(final String name) { public Log4JLogger(final String name) {
this.name = name; this.name = name;
@@ -106,6 +109,8 @@ public class Log4JLogger implements Log, Serializable {
/** /**
* For use with a log4j factory. * For use with a log4j factory.
*
* @param logger Logger.
*/ */
public Log4JLogger(final Logger logger) { public Log4JLogger(final Logger logger) {
if (logger == null) { if (logger == null) {
@@ -259,7 +264,9 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Return the native Logger instance we are using. * Gets the native Logger instance we are using.
*
* @return the native Logger instance we are using.
*/ */
public Logger getLogger() { public Logger getLogger() {
Logger result = logger; Logger result = logger;
@@ -275,7 +282,7 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Check whether the Log4j Logger used is enabled for {@code DEBUG} priority. * Tests whether the Log4j Logger used is enabled for {@code DEBUG} priority.
*/ */
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
@@ -283,7 +290,7 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Check whether the Log4j Logger used is enabled for {@code ERROR} priority. * Tests whether the Log4j Logger used is enabled for {@code ERROR} priority.
*/ */
@Override @Override
public boolean isErrorEnabled() { public boolean isErrorEnabled() {
@@ -291,7 +298,7 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Check whether the Log4j Logger used is enabled for {@code FATAL} priority. * Tests whether the Log4j Logger used is enabled for {@code FATAL} priority.
*/ */
@Override @Override
public boolean isFatalEnabled() { public boolean isFatalEnabled() {
@@ -299,7 +306,7 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Check whether the Log4j Logger used is enabled for {@code INFO} priority. * Tests whether the Log4j Logger used is enabled for {@code INFO} priority.
*/ */
@Override @Override
public boolean isInfoEnabled() { public boolean isInfoEnabled() {
@@ -307,7 +314,7 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Check whether the Log4j Logger used is enabled for {@code TRACE} priority. * Tests whether the Log4j Logger used is enabled for {@code TRACE} priority.
* When using a log4j version that does not support the TRACE level, this call * When using a log4j version that does not support the TRACE level, this call
* will report whether {@code DEBUG} is enabled or not. * will report whether {@code DEBUG} is enabled or not.
*/ */
@@ -317,7 +324,7 @@ public class Log4JLogger implements Log, Serializable {
} }
/** /**
* Check whether the Log4j Logger used is enabled for {@code WARN} priority. * Tests whether the Log4j Logger used is enabled for {@code WARN} priority.
*/ */
@Override @Override
public boolean isWarnEnabled() { public boolean isWarnEnabled() {

View File

@@ -78,7 +78,7 @@ public class LogFactoryImpl extends LogFactory {
/** /**
* An empty immutable {@code String} array. * An empty immutable {@code String} array.
*/ */
private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final String[] EMPTY_STRING_ARRAY = {};
// ----------------------------------------------------------- Constructors // ----------------------------------------------------------- Constructors
@@ -376,8 +376,10 @@ public class LogFactoryImpl extends LogFactory {
// ------------------------------------------------------ // ------------------------------------------------------
/** /**
* Gets the context classloader. * Gets the context ClassLoader.
* This method is a workaround for a java 1.2 compiler bug. * This method is a workaround for a java 1.2 compiler bug.
*
* @return the context ClassLoader
* @since 1.1 * @since 1.1
*/ */
protected static ClassLoader getContextClassLoader() throws LogConfigurationException { protected static ClassLoader getContextClassLoader() throws LogConfigurationException {
@@ -386,15 +388,19 @@ public class LogFactoryImpl extends LogFactory {
/** /**
* Workaround for bug in Java1.2; in theory this method is not needed. * Workaround for bug in Java1.2; in theory this method is not needed.
* See LogFactory.isDiagnosticsEnabled. *
* @return Same as {@link LogFactory#isDiagnosticsEnabled()}.
* @see LogFactory#isDiagnosticsEnabled()
*/ */
protected static boolean isDiagnosticsEnabled() { protected static boolean isDiagnosticsEnabled() {
return LogFactory.isDiagnosticsEnabled(); return LogFactory.isDiagnosticsEnabled();
} }
/** /**
* Workaround for bug in Java1.2; in theory this method is not needed. * Workaround for bug in Java1.2; in theory this method is not needed. {@link LogFactory#getClassLoader(Class)}.
* See LogFactory.getClassLoader. *
* @param clazz See {@link LogFactory#getClassLoader(Class)}.
* @return See {@link LogFactory#getClassLoader(Class)}.
* @since 1.1 * @since 1.1
*/ */
protected static ClassLoader getClassLoader(final Class clazz) { protected static ClassLoader getClassLoader(final Class clazz) {
@@ -454,11 +460,10 @@ public class LogFactoryImpl extends LogFactory {
} }
/** /**
* Return the fully qualified Java classname of the {@link Log} * Return the fully qualified Java classname of the {@link Log} implementation we will be using.
* implementation we will be using.
* *
* @deprecated Never invoked by this class; subclasses should not assume * @return the fully qualified Java classname of the {@link Log} implementation we will be using.
* it will be. * @deprecated Never invoked by this class; subclasses should not assume it will be.
*/ */
@Deprecated @Deprecated
protected String getLogClassName() { protected String getLogClassName() {
@@ -471,19 +476,20 @@ public class LogFactoryImpl extends LogFactory {
/** /**
* <p>Return the {@code Constructor} that can be called to instantiate * <p>
* new {@link org.apache.commons.logging.Log} instances.</p> * Return the {@code Constructor} that can be called to instantiate new {@link org.apache.commons.logging.Log} instances.
* </p>
* *
* <p><strong>IMPLEMENTATION NOTE</strong> - Race conditions caused by * <p>
* calling this method from more than one thread are ignored, because * <strong>IMPLEMENTATION NOTE</strong> - Race conditions caused by calling this method from more than one thread are ignored, because the same
* the same {@code Constructor} instance will ultimately be derived * {@code Constructor} instance will ultimately be derived in all circumstances.
* in all circumstances.</p> * </p>
* *
* @throws LogConfigurationException if a suitable constructor * @return the {@code Constructor} that can be called to instantiate new {@link org.apache.commons.logging.Log} instances.
* cannot be returned
* *
* @deprecated Never invoked by this class; subclasses should not assume * @throws LogConfigurationException if a suitable constructor cannot be returned
* it will be. *
* @deprecated Never invoked by this class; subclasses should not assume it will be.
*/ */
@Deprecated @Deprecated
protected Constructor getLogConstructor() protected Constructor getLogConstructor()
@@ -498,10 +504,10 @@ public class LogFactoryImpl extends LogFactory {
} }
/** /**
* Is <em>JDK 1.3 with Lumberjack</em> logging available? * Tests whether <em>JDK 1.3 with Lumberjack</em> logging available.
* *
* @deprecated Never invoked by this class; subclasses should not assume * @return whether <em>JDK 1.3 with Lumberjack</em> logging available.
* it will be. * @deprecated Never invoked by this class; subclasses should not assume it will be.
*/ */
@Deprecated @Deprecated
protected boolean isJdk13LumberjackAvailable() { protected boolean isJdk13LumberjackAvailable() {
@@ -511,42 +517,37 @@ public class LogFactoryImpl extends LogFactory {
} }
/** /**
* Return {@code true} if <em>JDK 1.4 or later</em> logging * Tests {@code true} whether <em>JDK 1.4 or later</em> logging is available. Also checks that the {@code Throwable} class supports {@code getStackTrace()},
* is available. Also checks that the {@code Throwable} class * which is required by Jdk14Logger.
* supports {@code getStackTrace()}, which is required by
* Jdk14Logger.
* *
* @deprecated Never invoked by this class; subclasses should not assume * @return Whether <em>JDK 1.4 or later</em> logging is available.
* it will be. *
* @deprecated Never invoked by this class; subclasses should not assume it will be.
*/ */
@Deprecated @Deprecated
protected boolean isJdk14Available() { protected boolean isJdk14Available() {
return isLogLibraryAvailable( return isLogLibraryAvailable("Jdk14", "org.apache.commons.logging.impl.Jdk14Logger");
"Jdk14",
"org.apache.commons.logging.impl.Jdk14Logger");
} }
/** /**
* Is a <em>Log4J</em> implementation available? * Tests whether a <em>Log4J</em> implementation available.
* *
* @deprecated Never invoked by this class; subclasses should not assume * @return whether a <em>Log4J</em> implementation available.
* it will be. *
* @deprecated Never invoked by this class; subclasses should not assume it will be.
*/ */
@Deprecated @Deprecated
protected boolean isLog4JAvailable() { protected boolean isLog4JAvailable() {
return isLogLibraryAvailable( return isLogLibraryAvailable("Log4J", LOGGING_IMPL_LOG4J_LOGGER);
"Log4J",
LOGGING_IMPL_LOG4J_LOGGER);
} }
/** /**
* Create and return a new {@link org.apache.commons.logging.Log} * Create and return a new {@link org.apache.commons.logging.Log} instance for the specified name.
* instance for the specified name.
* *
* @param name Name of the new logger * @param name Name of the new logger
* @return a new {@link org.apache.commons.logging.Log}
* *
* @throws LogConfigurationException if a new instance cannot * @throws LogConfigurationException if a new instance cannot be created
* be created
*/ */
protected Log newInstance(final String name) throws LogConfigurationException { protected Log newInstance(final String name) throws LogConfigurationException {
Log instance; Log instance;
@@ -609,12 +610,7 @@ public class LogFactoryImpl extends LogFactory {
private static ClassLoader getContextClassLoaderInternal() private static ClassLoader getContextClassLoaderInternal()
throws LogConfigurationException { throws LogConfigurationException {
return (ClassLoader)AccessController.doPrivileged( return (ClassLoader)AccessController.doPrivileged(
new PrivilegedAction() { (PrivilegedAction) LogFactory::directGetContextClassLoader);
@Override
public Object run() {
return LogFactory.directGetContextClassLoader();
}
});
} }
/** /**
@@ -629,12 +625,7 @@ public class LogFactoryImpl extends LogFactory {
private static String getSystemProperty(final String key, final String def) private static String getSystemProperty(final String key, final String def)
throws SecurityException { throws SecurityException {
return (String) AccessController.doPrivileged( return (String) AccessController.doPrivileged(
new PrivilegedAction() { (PrivilegedAction) () -> System.getProperty(key, def));
@Override
public Object run() {
return System.getProperty(key, def);
}
});
} }
/** /**
@@ -647,12 +638,7 @@ public class LogFactoryImpl extends LogFactory {
private ClassLoader getParentClassLoader(final ClassLoader cl) { private ClassLoader getParentClassLoader(final ClassLoader cl) {
try { try {
return (ClassLoader)AccessController.doPrivileged( return (ClassLoader)AccessController.doPrivileged(
new PrivilegedAction() { (PrivilegedAction) () -> cl.getParent());
@Override
public Object run() {
return cl.getParent();
}
});
} catch (final SecurityException ex) { } catch (final SecurityException ex) {
logDiagnostic("[SECURITY] Unable to obtain parent classloader"); logDiagnostic("[SECURITY] Unable to obtain parent classloader");
return null; return null;

View File

@@ -63,7 +63,9 @@ public class LogKitLogger implements Log, Serializable {
// --------------------------------------------------------- Public Methods // --------------------------------------------------------- Public Methods
/** /**
* Return the underlying Logger we are using. * Gets the underlying Logger we are using.
*
* @return the underlying Logger we are using.
*/ */
public Logger getLogger() { public Logger getLogger() {
Logger result = logger; Logger result = logger;

View File

@@ -21,8 +21,7 @@ import java.io.Serializable;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
/** /**
* Trivial implementation of Log that throws away all messages. No * Trivial implementation of Log that throws away all messages. No configurable system properties are supported.
* configurable system properties are supported.
*/ */
public class NoOpLog implements Log, Serializable { public class NoOpLog implements Log, Serializable {
@@ -30,45 +29,76 @@ public class NoOpLog implements Log, Serializable {
private static final long serialVersionUID = 561423906191706148L; private static final long serialVersionUID = 561423906191706148L;
/** Convenience constructor */ /** Convenience constructor */
public NoOpLog() { } public NoOpLog() {
/** Base constructor */ }
public NoOpLog(final String name) { }
/**
* Base constructor
*
* @param name unused.
*/
public NoOpLog(final String name) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void trace(final Object message) { } public void trace(final Object message) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void trace(final Object message, final Throwable t) { } public void trace(final Object message, final Throwable t) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void debug(final Object message) { } public void debug(final Object message) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void debug(final Object message, final Throwable t) { } public void debug(final Object message, final Throwable t) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void info(final Object message) { } public void info(final Object message) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void info(final Object message, final Throwable t) { } public void info(final Object message, final Throwable t) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void warn(final Object message) { } public void warn(final Object message) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void warn(final Object message, final Throwable t) { } public void warn(final Object message, final Throwable t) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void error(final Object message) { } public void error(final Object message) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void error(final Object message, final Throwable t) { } public void error(final Object message, final Throwable t) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void fatal(final Object message) { } public void fatal(final Object message) {
}
/** Do nothing */ /** Do nothing */
@Override @Override
public void fatal(final Object message, final Throwable t) { } public void fatal(final Object message, final Throwable t) {
}
/** /**
* Debug is never enabled. * Debug is never enabled.
@@ -76,7 +106,9 @@ public class NoOpLog implements Log, Serializable {
* @return false * @return false
*/ */
@Override @Override
public final boolean isDebugEnabled() { return false; } public final boolean isDebugEnabled() {
return false;
}
/** /**
* Error is never enabled. * Error is never enabled.
@@ -84,7 +116,9 @@ public class NoOpLog implements Log, Serializable {
* @return false * @return false
*/ */
@Override @Override
public final boolean isErrorEnabled() { return false; } public final boolean isErrorEnabled() {
return false;
}
/** /**
* Fatal is never enabled. * Fatal is never enabled.
@@ -92,7 +126,9 @@ public class NoOpLog implements Log, Serializable {
* @return false * @return false
*/ */
@Override @Override
public final boolean isFatalEnabled() { return false; } public final boolean isFatalEnabled() {
return false;
}
/** /**
* Info is never enabled. * Info is never enabled.
@@ -100,7 +136,9 @@ public class NoOpLog implements Log, Serializable {
* @return false * @return false
*/ */
@Override @Override
public final boolean isInfoEnabled() { return false; } public final boolean isInfoEnabled() {
return false;
}
/** /**
* Trace is never enabled. * Trace is never enabled.
@@ -108,7 +146,9 @@ public class NoOpLog implements Log, Serializable {
* @return false * @return false
*/ */
@Override @Override
public final boolean isTraceEnabled() { return false; } public final boolean isTraceEnabled() {
return false;
}
/** /**
* Warn is never enabled. * Warn is never enabled.
@@ -116,5 +156,7 @@ public class NoOpLog implements Log, Serializable {
* @return false * @return false
*/ */
@Override @Override
public final boolean isWarnEnabled() { return false; } public final boolean isWarnEnabled() {
return false;
}
} }

View File

@@ -259,6 +259,8 @@ public class SimpleLog implements Log, Serializable {
/** /**
* Get logging level. * Get logging level.
*
* @return logging level.
*/ */
public int getLevel() { public int getLevel() {
return currentLogLevel; return currentLogLevel;
@@ -358,9 +360,10 @@ public class SimpleLog implements Log, Serializable {
} }
/** /**
* Is the given log level currently enabled? * Tests whether the given log level currently enabled.
* *
* @param logLevel is this level enabled? * @param logLevel is this level enabled?
* @return whether the given log level currently enabled.
*/ */
protected boolean isLevelEnabled(final int logLevel) { protected boolean isLevelEnabled(final int logLevel) {
// log level are numerically ordered so can use simple numeric // log level are numerically ordered so can use simple numeric

View File

@@ -124,9 +124,10 @@ public final class WeakHashtable extends Hashtable {
*/ */
private static final int PARTIAL_PURGE_COUNT = 10; private static final int PARTIAL_PURGE_COUNT = 10;
/* ReferenceQueue we check for gc'd keys */ /** ReferenceQueue we check for GC'd keys. */
private final ReferenceQueue queue = new ReferenceQueue(); private final ReferenceQueue queue = new ReferenceQueue();
/* Counter used to control how often we purge gc'd entries */
/** Counter used to control how often we purge gc'd entries. */
private int changeCount; private int changeCount;
/** /**