1
0

Remove obsolete comments

Move static block
This commit is contained in:
Gary Gregory
2023-11-19 09:51:16 -05:00
parent 98e559141d
commit 12ae9e6324
20 changed files with 138 additions and 206 deletions

View File

@@ -68,8 +68,7 @@ public abstract class LogFactory {
// lib and JCL have the necessary permissions even when the untrusted
// caller does not. That's a pretty hard route to exploit though.
// ----------------------------------------------------- Manifest Constants
/**
* The name ({@code priority}) of the key in the config file used to
* specify the priority of that particular config file. The associated value
@@ -203,16 +202,14 @@ public abstract class LogFactory {
*/
private static final int MAX_BROKEN_SERVICES = 3;
// ----------------------------------------------------------- Constructors
/**
* The previously constructed {@code LogFactory} instances, keyed by
* the {@code ClassLoader} with which it was created.
*/
protected static Hashtable factories;
// --------------------------------------------------------- Public Methods
/**
* Previously constructed {@code LogFactory} instance as in the
* {@code factories} map, but for the case where
@@ -231,39 +228,6 @@ public abstract class LogFactory {
@Deprecated
protected static volatile LogFactory nullClassLoaderFactory;
static {
// note: it's safe to call methods before initDiagnostics (though
// diagnostic output gets discarded).
final ClassLoader thisClassLoader = getClassLoader(LogFactory.class);
thisClassLoaderRef = new WeakReference<>(thisClassLoader);
// In order to avoid confusion where multiple instances of JCL are
// being used via different classloaders within the same app, we
// ensure each logged message has a prefix of form
// [LogFactory from classloader OID]
//
// Note that this prefix should be kept consistent with that
// in LogFactoryImpl. However here we don't need to output info
// about the actual *instance* of LogFactory, as all methods that
// output diagnostics from this class are static.
String classLoaderName;
try {
if (thisClassLoader == null) {
classLoaderName = "BOOTLOADER";
} else {
classLoaderName = objectId(thisClassLoader);
}
} catch (final SecurityException e) {
classLoaderName = "UNKNOWN";
}
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
DIAGNOSTICS_STREAM = initDiagnostics();
logClassLoaderEnvironment(LogFactory.class);
factories = createFactoryStore();
if (isDiagnosticsEnabled()) {
logDiagnostic("BOOTSTRAP COMPLETED");
}
}
/**
* Remember this factory, so later calls to LogFactory.getCachedFactory
* can return the previously created object (together with all its
@@ -567,8 +531,7 @@ public abstract class LogFactory {
return (LogFactory) factories.get(contextClassLoader);
}
// ------------------------------------------------------- Static Variables
/**
* Safely get access to the classloader for the specified class.
* <p>
@@ -728,8 +691,7 @@ public abstract class LogFactory {
return directGetContextClassLoader();
}
// --------------------------------------------------------- Static Methods
/**
* Calls LogFactory.directGetContextClassLoader under the control of an
* AccessController class. This means that java code running under a
@@ -1142,8 +1104,7 @@ public abstract class LogFactory {
(PrivilegedAction) () -> System.getProperty(key, def));
}
// ------------------------------------------------------ Protected Methods
/**
* Checks whether the supplied Throwable is one that needs to be
* re-thrown and ignores all others.
@@ -1656,9 +1617,18 @@ public abstract class LogFactory {
* @param name Name of the attribute to remove
*/
public abstract void removeAttribute(String name);
/**
* Sets the configuration attribute with the specified name. Calling
* this with a {@code null} value is equivalent to calling
* {@code removeAttribute(name)}.
*
* @param name Name of the attribute to set
* @param value Value of the attribute to set, or {@code null}
* to remove any setting for this attribute
*/
public abstract void setAttribute(String name, Object value);
// ----------------------------------------------------------------------
// Static initializer block to perform initialization at class load time.
//
// We can't do this in the class constructor, as there are many
// static methods on this class that can be called before any
@@ -1674,16 +1644,38 @@ public abstract class LogFactory {
//
// So the wisest thing to do is just to place this code at the very end
// of the class file.
// ----------------------------------------------------------------------
/**
* Sets the configuration attribute with the specified name. Calling
* this with a {@code null} value is equivalent to calling
* {@code removeAttribute(name)}.
*
* @param name Name of the attribute to set
* @param value Value of the attribute to set, or {@code null}
* to remove any setting for this attribute
*/
public abstract void setAttribute(String name, Object value);
static {
// note: it's safe to call methods before initDiagnostics (though
// diagnostic output gets discarded).
final ClassLoader thisClassLoader = getClassLoader(LogFactory.class);
thisClassLoaderRef = new WeakReference<>(thisClassLoader);
// In order to avoid confusion where multiple instances of JCL are
// being used via different classloaders within the same app, we
// ensure each logged message has a prefix of form
// [LogFactory from classloader OID]
//
// Note that this prefix should be kept consistent with that
// in LogFactoryImpl. However here we don't need to output info
// about the actual *instance* of LogFactory, as all methods that
// output diagnostics from this class are static.
String classLoaderName;
try {
if (thisClassLoader == null) {
classLoaderName = "BOOTLOADER";
} else {
classLoaderName = objectId(thisClassLoader);
}
} catch (final SecurityException e) {
classLoaderName = "UNKNOWN";
}
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
DIAGNOSTICS_STREAM = initDiagnostics();
logClassLoaderEnvironment(LogFactory.class);
factories = createFactoryStore();
if (isDiagnosticsEnabled()) {
logDiagnostic("BOOTSTRAP COMPLETED");
}
}
}

View File

@@ -53,8 +53,7 @@ import org.apache.commons.logging.impl.NoOpLog;
@Deprecated
public class LogSource {
// ------------------------------------------------------- Class Attributes
/**
* Logs.
*/
@@ -74,8 +73,7 @@ public class LogSource {
*/
private static final String[] EMPTY_STRING_ARRAY = {};
// ----------------------------------------------------- Class Initializers
static {
// Is Log4J Available?
@@ -132,8 +130,7 @@ public class LogSource {
}
// ------------------------------------------------------------ Constructor
/**
* Gets a {@code Log} instance by class.
*
@@ -144,8 +141,7 @@ public class LogSource {
return getInstance(clazz.getName());
}
// ---------------------------------------------------------- Class Methods
/**
* Gets a {@code Log} instance by class name.
*

View File

@@ -41,8 +41,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = -8649807923527610591L;
// ----------------------------------------------------- Instance Variables
/**
* This member variable simply ensures that any attempt to initialize
* this class in a pre-1.4 JVM will result in an ExceptionInInitializerError.
@@ -70,8 +69,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
/** Class and method found flag. */
private boolean classAndMethodFound;
// ----------------------------------------------------------- Constructors
/**
* Constructs a named instance of this Logger.
*
@@ -82,8 +80,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
logger = getLogger();
}
// --------------------------------------------------------- Public Methods
/**
* Logs a message with {@code java.util.logging.Level.FINE}.
*

View File

@@ -41,8 +41,7 @@ public class Jdk14Logger implements Log, Serializable {
*/
protected static final Level dummyLevel = Level.FINE;
// ----------------------------------------------------------- Constructors
/**
* The underlying Logger implementation we are using.
*/

View File

@@ -53,43 +53,9 @@ public class Log4JLogger implements Log, Serializable {
private static final Priority traceLevel;
static {
if (!Priority.class.isAssignableFrom(Level.class)) {
// nope, this is log4j 1.3, so force an ExceptionInInitializerError
throw new InstantiationError("Log4J 1.2 not available");
}
// Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
// versions do not. If TRACE is not available, then we have to map
// calls to Log.trace(...) onto the DEBUG level.
Priority _traceLevel;
try {
_traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
} catch (final Exception ex) {
// ok, trace not available
_traceLevel = Level.DEBUG;
}
traceLevel = _traceLevel;
}
/** Log to this logger */
private transient volatile Logger logger;
// ------------------------------------------------------------
// Static Initializer.
//
// Note that this must come after the static variable declarations
// otherwise initializer expressions associated with those variables
// will override any settings done here.
//
// Verify that log4j is available, and that it is version 1.2.
// If an ExceptionInInitializerError is generated, then LogFactoryImpl
// will treat that as meaning that the appropriate underlying logging
// library is just not present - if discovery is in progress then
// discovery will continue.
// ------------------------------------------------------------
/** Logger name */
private final String name;
@@ -333,4 +299,35 @@ public class Log4JLogger implements Log, Serializable {
public void warn(final Object message, final Throwable t) {
getLogger().log(FQCN, Level.WARN, message, t);
}
//
// Note that this must come after the static variable declarations
// otherwise initializer expressions associated with those variables
// will override any settings done here.
//
// Verify that log4j is available, and that it is version 1.2.
// If an ExceptionInInitializerError is generated, then LogFactoryImpl
// will treat that as meaning that the appropriate underlying logging
// library is just not present - if discovery is in progress then
// discovery will continue.
static {
if (!Priority.class.isAssignableFrom(Level.class)) {
// nope, this is log4j 1.3, so force an ExceptionInInitializerError
throw new InstantiationError("Log4J 1.2 not available");
}
// Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
// versions do not. If TRACE is not available, then we have to map
// calls to Log.trace(...) onto the DEBUG level.
Priority _traceLevel;
try {
_traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
} catch (final Exception ex) {
// ok, trace not available
_traceLevel = Level.DEBUG;
}
traceLevel = _traceLevel;
}
}

View File

@@ -80,16 +80,14 @@ public class LogFactoryImpl extends LogFactory {
*/
private static final String[] EMPTY_STRING_ARRAY = {};
// ----------------------------------------------------------- Constructors
/**
* The name ({@code org.apache.commons.logging.Log}) of the system
* property identifying our {@link Log} implementation class.
*/
public static final String LOG_PROPERTY = "org.apache.commons.logging.Log";
// ----------------------------------------------------- Manifest Constants
/**
* The deprecated system property used for backwards compatibility with
* old versions of JCL.
@@ -169,8 +167,7 @@ public class LogFactoryImpl extends LogFactory {
return LogFactory.getClassLoader(clazz);
}
// ----------------------------------------------------- Instance Variables
/**
* Gets the context ClassLoader.
* This method is a workaround for a java 1.2 compiler bug.
@@ -280,8 +277,7 @@ public class LogFactoryImpl extends LogFactory {
*/
protected Class[] logConstructorSignature = { String.class };
// --------------------------------------------------------- Public Methods
/**
* The one-argument {@code setLogFactory} method of the selected
* {@link org.apache.commons.logging.Log} method, if it exists.
@@ -492,13 +488,11 @@ public class LogFactoryImpl extends LogFactory {
return logAdapter;
}
// ------------------------------------------------------
// Static Methods
// Static Methods
//
// These methods only defined as workarounds for a java 1.2 bug;
// theoretically none of these are needed.
// ------------------------------------------------------
/**
* Attempts to create a Log instance for the given category name.
* Follows the discovery process described in the class javadoc.
@@ -664,8 +658,7 @@ public class LogFactoryImpl extends LogFactory {
return attributes.get(name);
}
// ------------------------------------------------------ Protected Methods
/**
* Return an array containing the names of all currently defined
* configuration attributes. If there are no such attributes, a zero

View File

@@ -40,16 +40,14 @@ public class LogKitLogger implements Log, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 3768538055836059519L;
// ------------------------------------------------------------- Attributes
/** Logging goes to this {@code LogKit} logger */
protected transient volatile Logger logger;
/** Name of this logger */
protected String name;
// ------------------------------------------------------------ Constructor
/**
* Constructs {@code LogKitLogger} which wraps the {@code LogKit}
* logger with given name.
@@ -61,8 +59,7 @@ public class LogKitLogger implements Log, Serializable {
this.logger = getLogger();
}
// --------------------------------------------------------- Public Methods
/**
* Logs a message with {@code org.apache.log.Priority.DEBUG}.
*
@@ -76,8 +73,7 @@ public class LogKitLogger implements Log, Serializable {
}
}
// ----------------------------------------------------- Log Implementation
/**
* Logs a message with {@code org.apache.log.Priority.DEBUG}.
*

View File

@@ -74,8 +74,7 @@ public class SimpleLog implements Log, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 136942970684951178L;
// ------------------------------------------------------- Class Attributes
/** All system properties used by {@code SimpleLog} start with this */
static protected final String systemPrefix = "org.apache.commons.logging.simplelog.";
@@ -111,8 +110,7 @@ public class SimpleLog implements Log, Serializable {
*/
static protected DateFormat dateFormatter;
// ---------------------------------------------------- Log Level Constants
/** "Trace" level logging. */
public static final int LOG_LEVEL_TRACE = 1;
/** "Debug" level logging. */
@@ -132,8 +130,7 @@ public class SimpleLog implements Log, Serializable {
/** Enable no logging levels */
public static final int LOG_LEVEL_OFF = LOG_LEVEL_FATAL + 1;
// ------------------------------------------------------------ Initializer
// Initialize class attributes.
// Load properties file, if found.
// Override with system properties.
@@ -247,8 +244,7 @@ public class SimpleLog implements Log, Serializable {
});
}
// ------------------------------------------------------------- Attributes
private static String getStringProperty(final String name) {
String prop = null;
try {
@@ -265,13 +261,11 @@ public class SimpleLog implements Log, Serializable {
/** The name of this simple log instance */
protected volatile String logName;
// ------------------------------------------------------------ Constructor
/** The current log level */
protected volatile int currentLogLevel;
// -------------------------------------------------------- Properties
/** The short name of this simple log instance */
private volatile String shortLogName;
@@ -320,8 +314,7 @@ public class SimpleLog implements Log, Serializable {
}
}
// -------------------------------------------------------- Logging Methods
/**
* Logs a message with
* {@code org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG}.
@@ -378,8 +371,7 @@ public class SimpleLog implements Log, Serializable {
}
}
// -------------------------------------------------------- Log Implementation
/**
* Log a message with {@code org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL}.
*

View File

@@ -41,8 +41,7 @@ import junit.framework.TestCase;
*/
public class FirstPriorityConfigTestCase extends TestCase {
// ------------------------------------------- JUnit Infrastructure Methods
/**
* Return the tests included in this test suite.
@@ -100,8 +99,7 @@ public class FirstPriorityConfigTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that the config file being used is the one containing
* the desired configId value.

View File

@@ -48,8 +48,7 @@ import junit.framework.TestCase;
public class PriorityConfigTestCase extends TestCase {
// ------------------------------------------- JUnit Infrastructure Methods
/**
* Return the tests included in this test suite.
@@ -118,8 +117,7 @@ public class PriorityConfigTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that the config file being used is the one containing
* the desired configId value.

View File

@@ -45,8 +45,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
protected static final String HANDLER_NAME = "org.apache.commons.logging.jdk14.TestHandler";
// ----------------------------------------------------------- Constructors
/**
* Make a class available in the system classloader even when its classfile is
@@ -84,8 +83,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
}
// ----------------------------------------------------- Instance Variables
/**
* Given the name of a class that is somewhere in the classpath of the provided
@@ -157,8 +155,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
protected LogManager manager;
// ------------------------------------------- JUnit Infrastructure Methods
/**
* <p>The message levels that should have been logged.</p>
@@ -237,8 +234,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
}
// ----------------------------------------------------------- Test Methods
// Log the messages with exceptions
protected void logExceptionMessages() {
@@ -311,8 +307,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
}
// -------------------------------------------------------- Support Methods
// Set up LogManager instance
protected void setUpManager(final String config) throws Exception {

View File

@@ -36,8 +36,7 @@ public class TestAppender extends AppenderSkeleton {
// The set of logged events for this appender
private final List events;
// ----------------------------------------------------- Instance Variables
/**
* Constructor.
@@ -47,8 +46,7 @@ public class TestAppender extends AppenderSkeleton {
}
// ------------------------------------------------------- Appender Methods
@Override
protected void append(final LoggingEvent event) {
final StandardTests.LogEvent lev = new StandardTests.LogEvent();

View File

@@ -39,8 +39,7 @@ import junit.framework.Test;
public class StandardTestCase extends AbstractLogTest {
// ----------------------------------------------------- Instance Variables
/**
* Return the tests included in this test suite.
@@ -65,8 +64,7 @@ public class StandardTestCase extends AbstractLogTest {
protected LogFactory factory;
// ------------------------------------------- JUnit Infrastructure Methods
/**
* <p>The {@link Log} implementation we have selected.</p>
@@ -101,8 +99,7 @@ public class StandardTestCase extends AbstractLogTest {
return new LogKitLogger(this.getClass().getName());
}
// ----------------------------------------------------------- Test Methods
/**
* Sets up instance variables required by this test case.
*/
@@ -147,8 +144,7 @@ public class StandardTestCase extends AbstractLogTest {
}
// -------------------------------------------------------- Support Methods
// Test Serializability of standard instance
public void testSerializable() throws Exception {
checkStandard();

View File

@@ -83,8 +83,7 @@ public class NoOpLogTestCase extends AbstractLogTest
}
// -------------------------------------------------------- Support Methods
// Test Serializability of standard instance
public void testSerializable() throws Exception {
Log log = LogFactory.getLog(this.getClass().getName());

View File

@@ -32,8 +32,7 @@ import junit.framework.Test;
*/
public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
// ----------------------------------------------------------- Constructors
/**
* Return the tests included in this test suite.
* <p>
@@ -79,8 +78,7 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
}
// ----------------------------------------------------------- Methods
/**
* Sets up system properties required by this unit test. Here, we
* set up the props defined in the parent class setProperties method,

View File

@@ -33,8 +33,7 @@ import org.apache.commons.logging.impl.SimpleLog;
public class DecoratedSimpleLog extends SimpleLog {
// ------------------------------------------------------------ Constructor
/**
* Generated serial version ID.
@@ -45,8 +44,7 @@ public class DecoratedSimpleLog extends SimpleLog {
protected ArrayList cache = new ArrayList();
// ------------------------------------------------------------- Properties
public DecoratedSimpleLog(final String name) {
super(name);
}
@@ -74,16 +72,14 @@ public class DecoratedSimpleLog extends SimpleLog {
}
// ------------------------------------------------------- Protected Methods
public String getLogName() {
return logName;
}
// ---------------------------------------------------------- Public Methods
public boolean getShowDateTime() {
return showDateTime;

View File

@@ -42,8 +42,7 @@ public class TcclDisabledTestCase extends TestCase {
public static final String MY_LOG_IMPL =
MY_LOG_PKG + ".MyLog";
// ------------------------------------------- JUnit Infrastructure Methods
/**
* Return the tests included in this test suite.
*/
@@ -104,8 +103,7 @@ public class TcclDisabledTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that MyLog is only loadable via the tccl.
*/

View File

@@ -42,8 +42,7 @@ public class TcclEnabledTestCase extends TestCase {
public static final String MY_LOG_IMPL =
MY_LOG_PKG + ".MyLog";
// ------------------------------------------- JUnit Infrastructure Methods
/**
* Return the tests included in this test suite.
*/
@@ -104,8 +103,7 @@ public class TcclEnabledTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that MyLogFactoryImpl is only loadable via the tccl.
*/

View File

@@ -41,8 +41,7 @@ public class TcclDisabledTestCase extends TestCase {
public static final String MY_LOG_FACTORY_IMPL =
MY_LOG_FACTORY_PKG + ".MyLogFactoryImpl";
// ------------------------------------------- JUnit Infrastructure Methods
/**
* Return the tests included in this test suite.
@@ -106,8 +105,7 @@ public class TcclDisabledTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that MyLogFactoryImpl is only loadable via the tccl.
*/

View File

@@ -35,8 +35,7 @@ import junit.framework.TestCase;
public class TcclEnabledTestCase extends TestCase {
// ------------------------------------------- JUnit Infrastructure Methods
/**
* Return the tests included in this test suite.
@@ -100,8 +99,7 @@ public class TcclEnabledTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that MyLogFactoryImpl is only loadable via the tccl.
*/