Checkstyle
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/decf01d0 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/decf01d0 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/decf01d0 Branch: refs/heads/LOG4J2-1136 Commit: decf01d0d08756dda5e55feee5749ede0791b030 Parents: 8606650 Author: rpopma <[email protected]> Authored: Thu Sep 24 17:00:37 2015 +0200 Committer: Ralph Goers <[email protected]> Committed: Sun Sep 27 10:49:28 2015 -0700 ---------------------------------------------------------------------- .../log4j/core/config/ReliabilityStrategy.java | 2 +- .../logging/log4j/core/util/FileUtils.java | 17 ++++++-------- .../logging/log4j/core/util/Integers.java | 24 +++++++++----------- .../logging/log4j/core/util/JndiCloser.java | 5 +++- .../logging/log4j/core/util/KeyValuePair.java | 8 +++---- .../apache/logging/log4j/core/util/Loader.java | 6 ++--- .../log4j/core/util/NanoClockFactory.java | 8 ++++--- .../logging/log4j/core/util/NetUtils.java | 10 ++++---- .../log4j/core/util/NullOutputStream.java | 2 +- .../logging/log4j/core/util/Patterns.java | 5 +--- .../logging/log4j/core/util/ReflectionUtil.java | 2 ++ .../logging/log4j/core/util/SetUtils.java | 9 ++++---- .../logging/log4j/core/util/Throwables.java | 24 +++++++++----------- .../logging/log4j/core/util/UuidUtil.java | 23 ++++++++----------- 14 files changed, 69 insertions(+), 76 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java index e85eef6..f21a92d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ReliabilityStrategy.java @@ -76,4 +76,4 @@ public interface ReliabilityStrategy { */ void beforeStopConfiguration(Configuration configuration); -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java index cab865c..c14954a 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java @@ -21,11 +21,9 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; -import java.util.regex.Pattern; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.status.StatusLogger; @@ -35,20 +33,18 @@ import org.apache.logging.log4j.status.StatusLogger; */ public final class FileUtils { - /** Constant for the file URL protocol.*/ + /** Constant for the file URL protocol. */ private static final String PROTOCOL_FILE = "file"; private static final String JBOSS_FILE = "vfsfile"; private static final Logger LOGGER = StatusLogger.getLogger(); - private static final Pattern WINDOWS_DIRECTORY_SEPARATOR = Pattern.compile("\\\\+"); private FileUtils() { } - /** - * Tries to convert the specified URI to a file object. If this fails, - * <b>null</b> is returned. + /** + * Tries to convert the specified URI to a file object. If this fails, <b>null</b> is returned. * * @param uri the URI * @return the resulting file object @@ -99,17 +95,18 @@ public final class FileUtils { /** * Asserts that the given directory exists and creates it if necessary. + * * @param dir the directory that shall exist * @param createDirectoryIfNotExisting specifies if the directory shall be created if it does not exist. * @throws java.io.IOException thrown if the directory could not be created. */ - public static void mkdir(final File dir, final boolean createDirectoryIfNotExisting ) throws IOException { + public static void mkdir(final File dir, final boolean createDirectoryIfNotExisting) throws IOException { // commons io FileUtils.forceMkdir would be useful here, we just want to omit this dependency if (!dir.exists()) { - if(!createDirectoryIfNotExisting) { + if (!createDirectoryIfNotExisting) { throw new IOException("The directory " + dir.getAbsolutePath() + " does not exist."); } - if(!dir.mkdirs()) { + if (!dir.mkdirs()) { throw new IOException("Could not create directory " + dir.getAbsolutePath()); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Integers.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Integers.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Integers.java index 7b09e5a..65f3750 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Integers.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Integers.java @@ -23,19 +23,18 @@ import org.apache.logging.log4j.util.Strings; */ public final class Integers { + private static final int BITS_PER_INT = 32; + private Integers() { } /** * Parses the string argument as a signed decimal integer. * - * @param s - * a {@code String} containing the {@code int} representation to parse, may be {@code null} or {@code ""} - * @param defaultValue - * the return value, use {@code defaultValue} if {@code s} is {@code null} or {@code ""} + * @param s a {@code String} containing the {@code int} representation to parse, may be {@code null} or {@code ""} + * @param defaultValue the return value, use {@code defaultValue} if {@code s} is {@code null} or {@code ""} * @return the integer value represented by the argument in decimal. - * @throws NumberFormatException - * if the string does not contain a parsable integer. + * @throws NumberFormatException if the string does not contain a parsable integer. */ public static int parseInt(final String s, final int defaultValue) { return Strings.isEmpty(s) ? defaultValue : Integer.parseInt(s); @@ -44,24 +43,23 @@ public final class Integers { /** * Parses the string argument as a signed decimal integer. * - * @param s - * a {@code String} containing the {@code int} representation to parse, may be {@code null} or {@code ""} + * @param s a {@code String} containing the {@code int} representation to parse, may be {@code null} or {@code ""} * @return the integer value represented by the argument in decimal. - * @throws NumberFormatException - * if the string does not contain a parsable integer. + * @throws NumberFormatException if the string does not contain a parsable integer. */ public static int parseInt(final String s) { return parseInt(s, 0); } - + /** - * Calculate the next power of 2, greater than or equal to x.<p> + * Calculate the next power of 2, greater than or equal to x. + * <p> * From Hacker's Delight, Chapter 3, Harry S. Warren Jr. * * @param x Value to round up * @return The next power of 2 from x inclusive */ public static int ceilingNextPowerOfTwo(final int x) { - return 1 << (32 - Integer.numberOfLeadingZeros(x - 1)); + return 1 << (BITS_PER_INT - Integer.numberOfLeadingZeros(x - 1)); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JndiCloser.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JndiCloser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JndiCloser.java index 204f75e..671c922 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JndiCloser.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/JndiCloser.java @@ -25,7 +25,10 @@ import javax.naming.NamingException; * * This class is separate from {@link Closer} because JNDI is not in Android. */ -public class JndiCloser { +public final class JndiCloser { + + private JndiCloser() { + } /** * Closes the specified {@code Context}. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/KeyValuePair.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/KeyValuePair.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/KeyValuePair.java index cc8a605..7375be6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/KeyValuePair.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/KeyValuePair.java @@ -95,13 +95,13 @@ public final class KeyValuePair implements Serializable { @PluginBuilderAttribute private String value; - public Builder setKey(final String key) { - this.key = key; + public Builder setKey(final String aKey) { + this.key = aKey; return this; } - public Builder setValue(final String value) { - this.value = value; + public Builder setValue(final String aValue) { + this.value = aValue; return this; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java index b52d74a..bb35752 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java @@ -34,6 +34,9 @@ public final class Loader { private static final String TSTR = "Caught Exception while in Loader.getResource. This may be innocuous."; + private Loader() { + } + /** * Returns the ClassLoader to use. * @return the ClassLoader. @@ -315,7 +318,4 @@ public final class Loader { return false; } } - - private Loader() { - } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java index 1eca7af..3ec37c2 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NanoClockFactory.java @@ -22,7 +22,10 @@ import java.util.Objects; /** * Creates the appropriate {@link NanoClock} instance for the current configuration. */ -public class NanoClockFactory { +public final class NanoClockFactory { + + private NanoClockFactory() { + } /** * Enum over the different kinds of nano clocks this factory can create. @@ -45,8 +48,7 @@ public class NanoClockFactory { public NanoClock createNanoClock() { return new SystemNanoClock(); } - }, - ; + }; public abstract NanoClock createNanoClock(); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NetUtils.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NetUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NetUtils.java index e9c55f4..e72beb6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NetUtils.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NetUtils.java @@ -31,7 +31,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.status.StatusLogger; /** - * + * Networking-related convenience methods. */ public final class NetUtils { @@ -43,9 +43,8 @@ public final class NetUtils { } /** - * This method gets the network name of the machine we are running on. - * Returns "UNKNOWN_LOCALHOST" in the unlikely case where the host name - * cannot be found. + * This method gets the network name of the machine we are running on. Returns "UNKNOWN_LOCALHOST" in the unlikely + * case where the host name cannot be found. * * @return String the name of the local host */ @@ -79,7 +78,8 @@ public final class NetUtils { } /** - * Converts a URI string or file path to a URI object + * Converts a URI string or file path to a URI object. + * * @param path the URI string or path * @return the URI object */ http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NullOutputStream.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NullOutputStream.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NullOutputStream.java index 7033f31..dfbd48d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NullOutputStream.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/NullOutputStream.java @@ -74,4 +74,4 @@ public class NullOutputStream extends OutputStream { public void write(final byte[] b) throws IOException { // to /dev/null } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Patterns.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Patterns.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Patterns.java index a1d7df0..1177148 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Patterns.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Patterns.java @@ -16,12 +16,10 @@ */ package org.apache.logging.log4j.core.util; -import java.util.regex.Pattern; - /** * Pattern strings used throughout Log4j. * - * @see Pattern + * @see java.util.regex.Pattern */ public final class Patterns { @@ -47,5 +45,4 @@ public final class Patterns { public static String toWhitespaceSeparator(final String separator) { return WHITESPACE + separator + WHITESPACE; } - } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ReflectionUtil.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ReflectionUtil.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ReflectionUtil.java index 06335e3..b05b625 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ReflectionUtil.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ReflectionUtil.java @@ -37,6 +37,7 @@ public final class ReflectionUtil { /** * Indicates whether or not a {@link Member} is both public and is contained in a public class. * + * @param <T> type of the object whose accessibility to test * @param member the Member to check for public accessibility (must not be {@code null}). * @return {@code true} if {@code member} is public and contained in a public class. * @throws NullPointerException if {@code member} is {@code null}. @@ -49,6 +50,7 @@ public final class ReflectionUtil { /** * Makes a {@link Member} {@link AccessibleObject#isAccessible() accessible} if the member is not public. * + * @param <T> type of the object to make accessible * @param member the Member to make accessible (must not be {@code null}). * @throws NullPointerException if {@code member} is {@code null}. */ http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java index db109d0..8ca5486 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java @@ -20,17 +20,16 @@ import java.util.HashSet; import java.util.Set; /** - * - * - * + * Set-related convenience methods. */ public final class SetUtils { - private SetUtils() {} + private SetUtils() { + } /** * Extracts the Strings from a Set that start with a given prefix. * - * @param set a Set of Strings (assumed to all be non-{@code null}) + * @param set a Set of Strings (assumed to all be non-{@code null}) * @param prefix the prefix to look for in the string set * @return an array of the matching strings from the given set */ http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java index 261932c..4f825e6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java @@ -31,14 +31,17 @@ import java.util.List; */ public final class Throwables { + private Throwables() { + } + /** * Has no effect on Java 6 and below. * * @param throwable a Throwable * @param suppressedThrowable a suppressed Throwable * @see Throwable#addSuppressed(Throwable) - * @deprecated If compiling on Java 7 and above use {@link Throwable#addSuppressed(Throwable)}. Marked as deprecated because Java 6 is - * deprecated. Will be removed in 2.5. + * @deprecated If compiling on Java 7 and above use {@link Throwable#addSuppressed(Throwable)}. + * Marked as deprecated because Java 6 is deprecated. Will be removed in 2.5. */ @Deprecated public static void addSuppressed(final Throwable throwable, final Throwable suppressedThrowable) { @@ -48,8 +51,7 @@ public final class Throwables { /** * Returns the deepest cause of the given {@code throwable}. * - * @param throwable - * the throwable to navigate + * @param throwable the throwable to navigate * @return the deepest throwable or the given throwable */ public static Throwable getRootCause(final Throwable throwable) { @@ -67,8 +69,8 @@ public final class Throwables { * @param throwable a Throwable * @return see Java 7's {@link Throwable#getSuppressed()} * @see Throwable#getSuppressed() - * @deprecated If compiling on Java 7 and above use {@link Throwable#getSuppressed()}. Marked as deprecated because Java 6 is - * deprecated. Will be removed 2.5. + * @deprecated If compiling on Java 7 and above use {@link Throwable#getSuppressed()}. Marked as deprecated because + * Java 6 is deprecated. Will be removed 2.5. */ @Deprecated public static Throwable[] getSuppressed(final Throwable throwable) { @@ -87,7 +89,7 @@ public final class Throwables { } /** - * Converts a Throwable stack trace into a List of Strings + * Converts a Throwable stack trace into a List of Strings. * * @param throwable the Throwable * @return a List of Strings @@ -124,8 +126,8 @@ public final class Throwables { * Rethrows a {@link Throwable}, wrapping checked exceptions into an {@link UndeclaredThrowableException}. * * @param t the Throwable to throw. - * @throws RuntimeException if {@code t} is a RuntimeException - * @throws Error if {@code t} is an Error + * @throws RuntimeException if {@code t} is a RuntimeException + * @throws Error if {@code t} is an Error * @throws UndeclaredThrowableException if {@code t} is a checked Exception * @since 2.1 */ @@ -138,8 +140,4 @@ public final class Throwables { } throw new UndeclaredThrowableException(t); } - - private Throwables() { - } - } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/decf01d0/log4j-core/src/main/java/org/apache/logging/log4j/core/util/UuidUtil.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/UuidUtil.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/UuidUtil.java index a163ff7..5203649 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/UuidUtil.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/UuidUtil.java @@ -36,27 +36,23 @@ import org.apache.logging.log4j.util.PropertiesUtil; * less than 10,000 IDs are generated per millisecond on the same device (as identified by its MAC address). */ public final class UuidUtil { - private static final Logger LOGGER = StatusLogger.getLogger(); /** * System property that may be used to seed the UUID generation with an integer value. */ public static final String UUID_SEQUENCE = "org.apache.logging.log4j.uuidSequence"; - private static final String ASSIGNED_SEQUENCES = "org.apache.logging.log4j.assignedSequences"; + private static final Logger LOGGER = StatusLogger.getLogger(); - private static final AtomicInteger count = new AtomicInteger(0); + private static final String ASSIGNED_SEQUENCES = "org.apache.logging.log4j.assignedSequences"; + private static final AtomicInteger COUNT = new AtomicInteger(0); private static final long TYPE1 = 0x1000L; - private static final byte VARIANT = (byte) 0x80; - private static final int SEQUENCE_MASK = 0x3FFF; - private static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; + private static final long INITIAL_UUID_SEQNO = PropertiesUtil.getProperties().getLongProperty(UUID_SEQUENCE, 0); - private static final long uuidSequence = PropertiesUtil.getProperties().getLongProperty(UUID_SEQUENCE, 0); - - private static final long least; + private static final long LEAST; private static final long LOW_MASK = 0xffffffffL; private static final long MID_MASK = 0xffff00000000L; @@ -84,7 +80,7 @@ public final class UuidUtil { } System.arraycopy(mac, index, node, index + 2, length); final ByteBuffer buf = ByteBuffer.wrap(node); - long rand = uuidSequence; + long rand = INITIAL_UUID_SEQNO; String assigned = PropertiesUtil.getProperties().getStringProperty(ASSIGNED_SEQUENCES); long[] sequences; if (assigned == null) { @@ -118,7 +114,7 @@ public final class UuidUtil { assigned = assigned == null ? Long.toString(rand) : assigned + ',' + Long.toString(rand); System.setProperty(ASSIGNED_SEQUENCES, assigned); - least = buf.getLong() | rand << SHIFT_6; + LEAST = buf.getLong() | rand << SHIFT_6; } @@ -145,12 +141,12 @@ public final class UuidUtil { public static UUID getTimeBasedUuid() { final long time = ((System.currentTimeMillis() * HUNDRED_NANOS_PER_MILLI) + - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) + (count.incrementAndGet() % HUNDRED_NANOS_PER_MILLI); + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) + (COUNT.incrementAndGet() % HUNDRED_NANOS_PER_MILLI); final long timeLow = (time & LOW_MASK) << SHIFT_4; final long timeMid = (time & MID_MASK) >> SHIFT_2; final long timeHi = (time & HIGH_MASK) >> SHIFT_6; final long most = timeLow | timeMid | TYPE1 | timeHi; - return new UUID(most, least); + return new UUID(most, LEAST); } /** @@ -185,6 +181,7 @@ public final class UuidUtil { mac = localHost.getAddress(); } } catch (final UnknownHostException ignored) { + // ignored } return mac; }
