diff --git a/src/main/java/org/apache/commons/logging/LogFactory.java b/src/main/java/org/apache/commons/logging/LogFactory.java index be9acd0..2d8eb08 100644 --- a/src/main/java/org/apache/commons/logging/LogFactory.java +++ b/src/main/java/org/apache/commons/logging/LogFactory.java @@ -133,7 +133,7 @@ public abstract class LogFactory { * generated by LogFactory or LogFactoryImpl. When non-null, * interesting events will be written to the specified object. */ - private static PrintStream diagnosticsStream; + private static final PrintStream DIAGNOSTICS_STREAM; /** * A string that gets prefixed to every message output by the @@ -1088,7 +1088,7 @@ public abstract class LogFactory { // has been specified. Several well known containers use this mechanism to adapt JCL // to their native logging system. // - final StringBuffer msg = new StringBuffer(); + final StringBuilder msg = new StringBuilder(); msg.append("The application has specified that a custom LogFactory implementation "); msg.append("should be used but Class '"); msg.append(factoryClass); @@ -1503,7 +1503,7 @@ public abstract class LogFactory { * @since 1.1 */ protected static boolean isDiagnosticsEnabled() { - return diagnosticsStream != null; + return DIAGNOSTICS_STREAM != null; } /** @@ -1525,10 +1525,10 @@ public abstract class LogFactory { * @param msg is the diagnostic message to be output. */ private static final void logDiagnostic(final String msg) { - if (diagnosticsStream != null) { - diagnosticsStream.print(diagnosticPrefix); - diagnosticsStream.println(msg); - diagnosticsStream.flush(); + if (DIAGNOSTICS_STREAM != null) { + DIAGNOSTICS_STREAM.print(diagnosticPrefix); + DIAGNOSTICS_STREAM.println(msg); + DIAGNOSTICS_STREAM.flush(); } } @@ -1539,9 +1539,9 @@ public abstract class LogFactory { * @since 1.1 */ protected static final void logRawDiagnostic(final String msg) { - if (diagnosticsStream != null) { - diagnosticsStream.println(msg); - diagnosticsStream.flush(); + if (DIAGNOSTICS_STREAM != null) { + DIAGNOSTICS_STREAM.println(msg); + DIAGNOSTICS_STREAM.flush(); } } @@ -1616,7 +1616,7 @@ public abstract class LogFactory { return; } if (classLoader != null) { - final StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:"); + final StringBuilder buf = new StringBuilder(prefix + "ClassLoader tree:"); for(;;) { buf.append(objectId(classLoader)); if (classLoader == systemClassLoader) { @@ -1704,7 +1704,7 @@ public abstract class LogFactory { classLoaderName = "UNKNOWN"; } diagnosticPrefix = "[LogFactory from " + classLoaderName + "] "; - diagnosticsStream = initDiagnostics(); + DIAGNOSTICS_STREAM = initDiagnostics(); logClassLoaderEnvironment(LogFactory.class); factories = createFactoryStore(); if (isDiagnosticsEnabled()) { diff --git a/src/main/java/org/apache/commons/logging/LogSource.java b/src/main/java/org/apache/commons/logging/LogSource.java index 60f733a..baacded 100644 --- a/src/main/java/org/apache/commons/logging/LogSource.java +++ b/src/main/java/org/apache/commons/logging/LogSource.java @@ -68,6 +68,11 @@ public class LogSource { /** Constructor for current log class */ static protected Constructor logImplctor; + /** + * An empty immutable {@code String} array. + */ + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + // ----------------------------------------------------- Class Initializers static { @@ -215,6 +220,6 @@ public class LogSource { * all logs known to me. */ static public String[] getLogNames() { - return (String[]) logs.keySet().toArray(new String[logs.size()]); + return (String[]) logs.keySet().toArray(EMPTY_STRING_ARRAY); } } diff --git a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java index deaf8df..d967911 100644 --- a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java +++ b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java @@ -77,6 +77,11 @@ public class LogFactoryImpl extends LogFactory { private static final String PKG_IMPL="org.apache.commons.logging.impl."; private static final int PKG_LEN = PKG_IMPL.length(); + /** + * An empty immutable {@code String} array. + */ + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + // ----------------------------------------------------------- Constructors /** @@ -254,7 +259,7 @@ public class LogFactoryImpl extends LogFactory { */ @Override public String[] getAttributeNames() { - return (String[]) attributes.keySet().toArray(new String[attributes.size()]); + return (String[]) attributes.keySet().toArray(EMPTY_STRING_ARRAY); } /** @@ -1360,7 +1365,7 @@ public class LogFactoryImpl extends LogFactory { } if (!allowFlawedHierarchy) { - final StringBuffer msg = new StringBuffer(); + final StringBuilder msg = new StringBuilder(); msg.append("Terminating logging for this context "); msg.append("due to bad log hierarchy. "); msg.append("You have more than one version of '"); @@ -1373,7 +1378,7 @@ public class LogFactoryImpl extends LogFactory { } if (isDiagnosticsEnabled()) { - final StringBuffer msg = new StringBuffer(); + final StringBuilder msg = new StringBuilder(); msg.append("Warning: bad log hierarchy. "); msg.append("You have more than one version of '"); msg.append(Log.class.getName()); @@ -1383,7 +1388,7 @@ public class LogFactoryImpl extends LogFactory { } else { // this is just a bad adapter class if (!allowFlawedDiscovery) { - final StringBuffer msg = new StringBuffer(); + final StringBuilder msg = new StringBuilder(); msg.append("Terminating logging for this context. "); msg.append("Log class '"); msg.append(badClass.getName()); @@ -1396,7 +1401,7 @@ public class LogFactoryImpl extends LogFactory { } if (isDiagnosticsEnabled()) { - final StringBuffer msg = new StringBuffer(); + final StringBuilder msg = new StringBuilder(); msg.append("[WARNING] Log class '"); msg.append(badClass.getName()); msg.append("' does not implement the Log interface."); diff --git a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java index 3baf807..ae24c49 100644 --- a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java +++ b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java @@ -86,7 +86,7 @@ public class SimpleLog implements Log, Serializable { static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz"; /** Include the instance name in the log message? */ - static volatile protected boolean showLogName = false; + static volatile protected boolean showLogName; /** Include the short name ( last component ) of the logger in the log * message. Defaults to true - otherwise we'll be lost in a flood of @@ -95,7 +95,7 @@ public class SimpleLog implements Log, Serializable { static volatile protected boolean showShortName = true; /** Include the current time in the log message */ - static volatile protected boolean showDateTime = false; + static volatile protected boolean showDateTime; /** The date and time format to use in the log message */ static volatile protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT; @@ -193,11 +193,11 @@ public class SimpleLog implements Log, Serializable { // ------------------------------------------------------------- Attributes /** The name of this simple log instance */ - protected volatile String logName = null; + protected volatile String logName; /** The current log level */ protected volatile int currentLogLevel; /** The short name of this simple log instance */ - private volatile String shortLogName = null; + private volatile String shortLogName; // ------------------------------------------------------------ Constructor diff --git a/src/main/java/org/apache/commons/logging/impl/WeakHashtable.java b/src/main/java/org/apache/commons/logging/impl/WeakHashtable.java index 3eea803..9b48bbc 100644 --- a/src/main/java/org/apache/commons/logging/impl/WeakHashtable.java +++ b/src/main/java/org/apache/commons/logging/impl/WeakHashtable.java @@ -127,7 +127,7 @@ public final class WeakHashtable extends Hashtable { /* ReferenceQueue we check for gc'd keys */ private final ReferenceQueue queue = new ReferenceQueue(); /* Counter used to control how often we purge gc'd entries */ - private int changeCount = 0; + private int changeCount; /** * Constructs a WeakHashtable with the Hashtable default diff --git a/src/test/java/org/apache/commons/logging/PathableClassLoader.java b/src/test/java/org/apache/commons/logging/PathableClassLoader.java index ee57ca2..4744d9a 100644 --- a/src/test/java/org/apache/commons/logging/PathableClassLoader.java +++ b/src/test/java/org/apache/commons/logging/PathableClassLoader.java @@ -395,7 +395,7 @@ public class PathableClassLoader extends URLClassLoader { /** * * Clean implementation of list function of - * {@link java.utils.Collection} added in JDK 1.4 + * {@link java.util.Collection} added in JDK 1.4 * @param en Enumeration, possibly null * @return ArrayList containing the enumerated * elements in the enumerated order, not null