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,7 +68,6 @@ 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
@@ -203,7 +202,6 @@ public abstract class LogFactory {
*/
private static final int MAX_BROKEN_SERVICES = 3;
// ----------------------------------------------------------- Constructors
/**
* The previously constructed {@code LogFactory} instances, keyed by
@@ -211,7 +209,6 @@ public abstract class LogFactory {
*/
protected static Hashtable factories;
// --------------------------------------------------------- Public Methods
/**
* Previously constructed {@code LogFactory} instance as in the
@@ -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,7 +531,6 @@ public abstract class LogFactory {
return (LogFactory) factories.get(contextClassLoader);
}
// ------------------------------------------------------- Static Variables
/**
* Safely get access to the classloader for the specified class.
@@ -728,7 +691,6 @@ public abstract class LogFactory {
return directGetContextClassLoader();
}
// --------------------------------------------------------- Static Methods
/**
* Calls LogFactory.directGetContextClassLoader under the control of an
@@ -1142,7 +1104,6 @@ public abstract class LogFactory {
(PrivilegedAction) () -> System.getProperty(key, def));
}
// ------------------------------------------------------ Protected Methods
/**
* Checks whether the supplied Throwable is one that needs to be
@@ -1657,8 +1618,17 @@ public abstract class LogFactory {
*/
public abstract void removeAttribute(String name);
// ----------------------------------------------------------------------
// Static initializer block to perform initialization at class load time.
/**
* 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);
//
// 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,7 +53,6 @@ import org.apache.commons.logging.impl.NoOpLog;
@Deprecated
public class LogSource {
// ------------------------------------------------------- Class Attributes
/**
* Logs.
@@ -74,7 +73,6 @@ public class LogSource {
*/
private static final String[] EMPTY_STRING_ARRAY = {};
// ----------------------------------------------------- Class Initializers
static {
@@ -132,7 +130,6 @@ public class LogSource {
}
// ------------------------------------------------------------ Constructor
/**
* Gets a {@code Log} instance by class.
@@ -144,7 +141,6 @@ public class LogSource {
return getInstance(clazz.getName());
}
// ---------------------------------------------------------- Class Methods
/**
* Gets a {@code Log} instance by class name.

View File

@@ -41,7 +41,6 @@ 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
@@ -70,7 +69,6 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
/** Class and method found flag. */
private boolean classAndMethodFound;
// ----------------------------------------------------------- Constructors
/**
* Constructs a named instance of this Logger.
@@ -82,7 +80,6 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
logger = getLogger();
}
// --------------------------------------------------------- Public Methods
/**
* Logs a message with {@code java.util.logging.Level.FINE}.

View File

@@ -41,7 +41,6 @@ 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,7 +80,6 @@ public class LogFactoryImpl extends LogFactory {
*/
private static final String[] EMPTY_STRING_ARRAY = {};
// ----------------------------------------------------------- Constructors
/**
* The name ({@code org.apache.commons.logging.Log}) of the system
@@ -88,7 +87,6 @@ public class LogFactoryImpl extends LogFactory {
*/
public static final String LOG_PROPERTY = "org.apache.commons.logging.Log";
// ----------------------------------------------------- Manifest Constants
/**
* The deprecated system property used for backwards compatibility with
@@ -169,7 +167,6 @@ public class LogFactoryImpl extends LogFactory {
return LogFactory.getClassLoader(clazz);
}
// ----------------------------------------------------- Instance Variables
/**
* Gets the context ClassLoader.
@@ -280,7 +277,6 @@ public class LogFactoryImpl extends LogFactory {
*/
protected Class[] logConstructorSignature = { String.class };
// --------------------------------------------------------- Public Methods
/**
* The one-argument {@code setLogFactory} method of the selected
@@ -492,12 +488,10 @@ public class LogFactoryImpl extends LogFactory {
return logAdapter;
}
// ------------------------------------------------------
// 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.
@@ -664,7 +658,6 @@ public class LogFactoryImpl extends LogFactory {
return attributes.get(name);
}
// ------------------------------------------------------ Protected Methods
/**
* Return an array containing the names of all currently defined

View File

@@ -40,7 +40,6 @@ 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;
@@ -48,7 +47,6 @@ public class LogKitLogger implements Log, Serializable {
/** Name of this logger */
protected String name;
// ------------------------------------------------------------ Constructor
/**
* Constructs {@code LogKitLogger} which wraps the {@code LogKit}
@@ -61,7 +59,6 @@ public class LogKitLogger implements Log, Serializable {
this.logger = getLogger();
}
// --------------------------------------------------------- Public Methods
/**
* Logs a message with {@code org.apache.log.Priority.DEBUG}.
@@ -76,7 +73,6 @@ public class LogKitLogger implements Log, Serializable {
}
}
// ----------------------------------------------------- Log Implementation
/**
* Logs a message with {@code org.apache.log.Priority.DEBUG}.

View File

@@ -74,7 +74,6 @@ 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,7 +110,6 @@ public class SimpleLog implements Log, Serializable {
*/
static protected DateFormat dateFormatter;
// ---------------------------------------------------- Log Level Constants
/** "Trace" level logging. */
public static final int LOG_LEVEL_TRACE = 1;
@@ -132,7 +130,6 @@ 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.
@@ -247,7 +244,6 @@ public class SimpleLog implements Log, Serializable {
});
}
// ------------------------------------------------------------- Attributes
private static String getStringProperty(final String name) {
String prop = null;
@@ -265,12 +261,10 @@ 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,7 +314,6 @@ public class SimpleLog implements Log, Serializable {
}
}
// -------------------------------------------------------- Logging Methods
/**
* Logs a message with
@@ -378,7 +371,6 @@ 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,7 +41,6 @@ import junit.framework.TestCase;
*/
public class FirstPriorityConfigTestCase extends TestCase {
// ------------------------------------------- JUnit Infrastructure Methods
/**
@@ -100,7 +99,6 @@ public class FirstPriorityConfigTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that the config file being used is the one containing

View File

@@ -48,7 +48,6 @@ import junit.framework.TestCase;
public class PriorityConfigTestCase extends TestCase {
// ------------------------------------------- JUnit Infrastructure Methods
/**
@@ -118,7 +117,6 @@ public class PriorityConfigTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that the config file being used is the one containing

View File

@@ -45,7 +45,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
protected static final String HANDLER_NAME = "org.apache.commons.logging.jdk14.TestHandler";
// ----------------------------------------------------------- Constructors
/**
@@ -84,7 +83,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
}
// ----------------------------------------------------- Instance Variables
/**
@@ -157,7 +155,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
protected LogManager manager;
// ------------------------------------------- JUnit Infrastructure Methods
/**
@@ -237,7 +234,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
}
// ----------------------------------------------------------- Test Methods
// Log the messages with exceptions
@@ -311,7 +307,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
}
// -------------------------------------------------------- Support Methods
// Set up LogManager instance

View File

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

View File

@@ -39,7 +39,6 @@ import junit.framework.Test;
public class StandardTestCase extends AbstractLogTest {
// ----------------------------------------------------- Instance Variables
/**
@@ -65,7 +64,6 @@ public class StandardTestCase extends AbstractLogTest {
protected LogFactory factory;
// ------------------------------------------- JUnit Infrastructure Methods
/**
@@ -101,7 +99,6 @@ public class StandardTestCase extends AbstractLogTest {
return new LogKitLogger(this.getClass().getName());
}
// ----------------------------------------------------------- Test Methods
/**
* Sets up instance variables required by this test case.
@@ -147,7 +144,6 @@ public class StandardTestCase extends AbstractLogTest {
}
// -------------------------------------------------------- Support Methods
// Test Serializability of standard instance
public void testSerializable() throws Exception {

View File

@@ -83,7 +83,6 @@ public class NoOpLogTestCase extends AbstractLogTest
}
// -------------------------------------------------------- Support Methods
// Test Serializability of standard instance
public void testSerializable() throws Exception {

View File

@@ -32,7 +32,6 @@ import junit.framework.Test;
*/
public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
// ----------------------------------------------------------- Constructors
/**
* Return the tests included in this test suite.
@@ -79,7 +78,6 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
}
// ----------------------------------------------------------- Methods
/**
* Sets up system properties required by this unit test. Here, we

View File

@@ -33,7 +33,6 @@ import org.apache.commons.logging.impl.SimpleLog;
public class DecoratedSimpleLog extends SimpleLog {
// ------------------------------------------------------------ Constructor
/**
@@ -45,7 +44,6 @@ public class DecoratedSimpleLog extends SimpleLog {
protected ArrayList cache = new ArrayList();
// ------------------------------------------------------------- Properties
public DecoratedSimpleLog(final String name) {
super(name);
@@ -74,7 +72,6 @@ public class DecoratedSimpleLog extends SimpleLog {
}
// ------------------------------------------------------- Protected Methods
public String getLogName() {
@@ -82,7 +79,6 @@ public class DecoratedSimpleLog extends SimpleLog {
}
// ---------------------------------------------------------- Public Methods
public boolean getShowDateTime() {

View File

@@ -42,7 +42,6 @@ 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,7 +103,6 @@ public class TcclDisabledTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that MyLog is only loadable via the tccl.

View File

@@ -42,7 +42,6 @@ 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,7 +103,6 @@ public class TcclEnabledTestCase extends TestCase {
LogFactory.releaseAll();
}
// ----------------------------------------------------------- Test Methods
/**
* Verify that MyLogFactoryImpl is only loadable via the tccl.

View File

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

View File

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