You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2020/11/17 17:23:48 UTC
[logging-log4j2] branch release-2.x updated: Fix generics compiler
warnings for the Class class. Fix missing type argument in test. Don't need
to nest some else clauses. Use Java 7 diamonds.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 9e6ab14 Fix generics compiler warnings for the Class class. Fix missing type argument in test. Don't need to nest some else clauses. Use Java 7 diamonds.
9e6ab14 is described below
commit 9e6ab141ac0c188609b2c961a34fb1dac8a44f3e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Nov 17 12:23:39 2020 -0500
Fix generics compiler warnings for the Class class. Fix missing type
argument in test. Don't need to nest some else clauses. Use Java 7
diamonds.
---
.../src/main/java/org/apache/log4j/Category.java | 12 +--
.../org/apache/log4j/helpers/OptionConverter.java | 6 +-
.../org/apache/log4j/xml/XmlConfiguration.java | 2 +-
.../core/config/status/StatusConfiguration.java | 2 +-
.../log4j/core/tools/picocli/CommandLine.java | 86 +++++++++++-----------
.../logging/log4j/core/util/OptionConverter.java | 5 +-
.../log4j/core/async/QueueFullAbstractTest.java | 2 +-
.../logging/log4j/core/lookup/MainLookupTest.java | 2 +-
.../logging/log4j/test/appender/ListAppender.java | 6 +-
.../org/apache/logging/log4j/jul/LogManager.java | 5 +-
.../logging/log4j/kubernetes/ContainerUtil.java | 3 +-
.../template/json/util/DummyRecyclerFactory.java | 2 +-
.../json/util/QueueingRecyclerFactory.java | 2 +-
.../log4j/perf/jmh/ReflectionBenchmark.java | 8 +-
.../perf/jmh/ThreadsafeDateFormatBenchmark.java | 6 +-
.../log4j/perf/jmh/TimeFormatBenchmark.java | 2 +-
.../logging/log4j/perf/util/StackDriver.java | 6 +-
.../boot/Log4j2CloudConfigLoggingSystem.java | 3 +-
.../logging/log4j/spring/boot/SpringLookup.java | 40 +++++-----
19 files changed, 93 insertions(+), 107 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
index 516e1f8..0211791 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
@@ -548,9 +548,9 @@ public class Category {
return logger.isEnabled(level);
}
- private ObjectRenderer get(Class clazz) {
+ private <T> ObjectRenderer get(Class<T> clazz) {
ObjectRenderer renderer = null;
- for(Class c = clazz; c != null; c = c.getSuperclass()) {
+ for (Class<? super T> c = clazz; c != null; c = c.getSuperclass()) {
renderer = rendererMap.get(c);
if (renderer != null) {
return renderer;
@@ -563,13 +563,13 @@ public class Category {
return null;
}
- ObjectRenderer searchInterfaces(Class c) {
+ ObjectRenderer searchInterfaces(Class<?> c) {
ObjectRenderer renderer = rendererMap.get(c);
- if(renderer != null) {
+ if (renderer != null) {
return renderer;
}
- Class[] ia = c.getInterfaces();
- for (Class clazz : ia) {
+ Class<?>[] ia = c.getInterfaces();
+ for (Class<?> clazz : ia) {
renderer = searchInterfaces(clazz);
if (renderer != null) {
return renderer;
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
index 59d3d9f..6a1854b 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
@@ -183,13 +183,11 @@ public class OptionConverter {
+ ":pri=[" + levelName + "]");
try {
- Class customLevel = LoaderUtil.loadClass(clazz);
+ Class<?> customLevel = LoaderUtil.loadClass(clazz);
// get a ref to the specified class' static method
// toLevel(String, org.apache.log4j.Level)
- Class[] paramTypes = new Class[]{String.class,
- org.apache.log4j.Level.class
- };
+ Class<?>[] paramTypes = new Class[] { String.class, org.apache.log4j.Level.class };
java.lang.reflect.Method toLevelMethod =
customLevel.getMethod("toLevel", paramTypes);
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/xml/XmlConfiguration.java b/log4j-1.2-api/src/main/java/org/apache/log4j/xml/XmlConfiguration.java
index 500f4d8..89dc460 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/xml/XmlConfiguration.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/xml/XmlConfiguration.java
@@ -84,7 +84,7 @@ public class XmlConfiguration extends Log4j1Configuration {
private static final String CONFIG_DEBUG_ATTR = "configDebug";
private static final String INTERNAL_DEBUG_ATTR = "debug";
private static final String EMPTY_STR = "";
- private static final Class[] ONE_STRING_PARAM = new Class[] { String.class };
+ private static final Class<?>[] ONE_STRING_PARAM = new Class[] { String.class };
private static final String dbfKey = "javax.xml.parsers.DocumentBuilderFactory";
private static final String THROWABLE_RENDERER_TAG = "throwableRenderer";
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java
index 813a358..95a512d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/status/StatusConfiguration.java
@@ -43,7 +43,7 @@ public class StatusConfiguration {
private static final Level DEFAULT_STATUS = Level.ERROR;
private static final Verbosity DEFAULT_VERBOSITY = Verbosity.QUIET;
- private final Collection<String> errorMessages = new LinkedBlockingQueue<String>();
+ private final Collection<String> errorMessages = new LinkedBlockingQueue<>();
private final StatusLogger logger = StatusLogger.getLogger();
private volatile boolean initialized;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java
index 4b73257..06b879f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java
@@ -139,11 +139,11 @@ public class CommandLine {
private String commandName = Help.DEFAULT_COMMAND_NAME;
private boolean overwrittenOptionsAllowed = false;
private boolean unmatchedArgumentsAllowed = false;
- private final List<String> unmatchedArguments = new ArrayList<String>();
+ private final List<String> unmatchedArguments = new ArrayList<>();
private CommandLine parent;
private boolean usageHelpRequested;
private boolean versionHelpRequested;
- private final List<String> versionLines = new ArrayList<String>();
+ private final List<String> versionLines = new ArrayList<>();
/**
* Constructs a new {@code CommandLine} interpreter with the specified annotated object.
@@ -208,7 +208,7 @@ public class CommandLine {
* @since 0.9.7
*/
public Map<String, CommandLine> getSubcommands() {
- return new LinkedHashMap<String, CommandLine>(interpreter.commands);
+ return new LinkedHashMap<>(interpreter.commands);
}
/**
* Returns the command that this is a subcommand of, or {@code null} if this is a top-level command.
@@ -563,7 +563,7 @@ public class CommandLine {
if (printHelpIfRequested(parsedCommands, out, ansi)) {
return null;
}
- final List<Object> result = new ArrayList<Object>();
+ final List<Object> result = new ArrayList<>();
for (final CommandLine parsed : parsedCommands) {
result.add(execute(parsed));
}
@@ -1856,12 +1856,12 @@ public class CommandLine {
* Helper class responsible for processing command line arguments.
*/
private class Interpreter {
- private final Map<String, CommandLine> commands = new LinkedHashMap<String, CommandLine>();
- private final Map<Class<?>, ITypeConverter<?>> converterRegistry = new HashMap<Class<?>, ITypeConverter<?>>();
- private final Map<String, Field> optionName2Field = new HashMap<String, Field>();
- private final Map<Character, Field> singleCharOption2Field = new HashMap<Character, Field>();
- private final List<Field> requiredFields = new ArrayList<Field>();
- private final List<Field> positionalParametersFields = new ArrayList<Field>();
+ private final Map<String, CommandLine> commands = new LinkedHashMap<>();
+ private final Map<Class<?>, ITypeConverter<?>> converterRegistry = new HashMap<>();
+ private final Map<String, Field> optionName2Field = new HashMap<>();
+ private final Map<Character, Field> singleCharOption2Field = new HashMap<>();
+ private final List<Field> requiredFields = new ArrayList<>();
+ private final List<Field> positionalParametersFields = new ArrayList<>();
private final Object command;
private boolean isHelpRequested;
private String separator = Help.DEFAULT_SEPARATOR;
@@ -1959,11 +1959,11 @@ public class CommandLine {
List<CommandLine> parse(final String... args) {
Assert.notNull(args, "argument array");
if (tracer.isInfo()) {tracer.info("Parsing %d command line args %s%n", args.length, Arrays.toString(args));}
- final Stack<String> arguments = new Stack<String>();
+ final Stack<String> arguments = new Stack<>();
for (int i = args.length - 1; i >= 0; i--) {
arguments.push(args[i]);
}
- final List<CommandLine> result = new ArrayList<CommandLine>();
+ final List<CommandLine> result = new ArrayList<>();
parse(result, arguments, args);
return result;
}
@@ -1975,10 +1975,10 @@ public class CommandLine {
CommandLine.this.usageHelpRequested = false;
final Class<?> cmdClass = this.command.getClass();
- if (tracer.isDebug()) {tracer.debug("Initializing %s: %d options, %d positional parameters, %d required, %d subcommands.%n", cmdClass.getName(), new HashSet<Field>(optionName2Field.values()).size(), positionalParametersFields.size(), requiredFields.size(), commands.size());}
+ if (tracer.isDebug()) {tracer.debug("Initializing %s: %d options, %d positional parameters, %d required, %d subcommands.%n", cmdClass.getName(), new HashSet<>(optionName2Field.values()).size(), positionalParametersFields.size(), requiredFields.size(), commands.size());}
parsedCommands.add(CommandLine.this);
- final List<Field> required = new ArrayList<Field>(requiredFields);
- final Set<Field> initialized = new HashSet<Field>();
+ final List<Field> required = new ArrayList<>(requiredFields);
+ final Set<Field> initialized = new HashSet<>();
Collections.sort(required, new PositionalParametersSorter());
try {
processArguments(parsedCommands, argumentStack, required, initialized, originalArgs);
@@ -2092,7 +2092,7 @@ public class CommandLine {
if (tracer.isDebug()) {tracer.debug("%s %s an option: %d matching prefix chars out of %d option names%n", arg, (result ? "resembles" : "doesn't resemble"), count, optionName2Field.size());}
return result;
}
- private void handleUnmatchedArguments(final String arg) {final Stack<String> args = new Stack<String>(); args.add(arg); handleUnmatchedArguments(args);}
+ private void handleUnmatchedArguments(final String arg) {final Stack<String> args = new Stack<>(); args.add(arg); handleUnmatchedArguments(args);}
private void handleUnmatchedArguments(final Stack<String> args) {
while (!args.isEmpty()) { unmatchedArguments.add(args.pop()); } // addAll would give args in reverse order
}
@@ -2372,7 +2372,7 @@ public class CommandLine {
final int length = existing == null ? 0 : Array.getLength(existing);
final Class<?> type = getTypeAttribute(field)[0];
final List<Object> converted = consumeArguments(field, annotation, arity, args, type, length, argDescription);
- final List<Object> newValues = new ArrayList<Object>();
+ final List<Object> newValues = new ArrayList<>();
for (int i = 0; i < length; i++) {
newValues.add(Array.get(existing, i));
}
@@ -2423,7 +2423,7 @@ public class CommandLine {
final Class<?> type,
final int originalSize,
final String argDescription) throws Exception {
- final List<Object> result = new ArrayList<Object>();
+ final List<Object> result = new ArrayList<>();
// first do the arity.min mandatory parameters
for (int i = 0; i < arity.min; i++) {
@@ -2547,15 +2547,15 @@ public class CommandLine {
private Collection<Object> createCollection(final Class<?> collectionClass) throws Exception {
if (collectionClass.isInterface()) {
if (List.class.isAssignableFrom(collectionClass)) {
- return new ArrayList<Object>();
+ return new ArrayList<>();
} else if (SortedSet.class.isAssignableFrom(collectionClass)) {
- return new TreeSet<Object>();
+ return new TreeSet<>();
} else if (Set.class.isAssignableFrom(collectionClass)) {
- return new LinkedHashSet<Object>();
+ return new LinkedHashSet<>();
} else if (Queue.class.isAssignableFrom(collectionClass)) {
- return new LinkedList<Object>(); // ArrayDeque is only available since 1.6
+ return new LinkedList<>(); // ArrayDeque is only available since 1.6
}
- return new ArrayList<Object>();
+ return new ArrayList<>();
}
// custom Collection implementation class must have default constructor
return (Collection<Object>) collectionClass.newInstance();
@@ -2564,7 +2564,7 @@ public class CommandLine {
try { // if it is an implementation class, instantiate it
return (Map<Object, Object>) mapClass.newInstance();
} catch (final Exception ignored) {}
- return new LinkedHashMap<Object, Object>();
+ return new LinkedHashMap<>();
}
private ITypeConverter<?> getTypeConverter(final Class<?> type, final Field field) {
final ITypeConverter<?> result = converterRegistry.get(type);
@@ -2823,7 +2823,7 @@ public class CommandLine {
private final static int usageHelpWidth = 80;
private final static int optionsColumnWidth = 2 + 2 + 1 + 24;
private final Object command;
- private final Map<String, Help> commands = new LinkedHashMap<String, Help>();
+ private final Map<String, Help> commands = new LinkedHashMap<>();
final ColorScheme colorScheme;
/** Immutable list of fields annotated with {@link Option}, in declaration order. */
@@ -2926,8 +2926,8 @@ public class CommandLine {
public Help(final Object command, final ColorScheme colorScheme) {
this.command = Assert.notNull(command, "command");
this.colorScheme = Assert.notNull(colorScheme, "colorScheme").applySystemProperties();
- final List<Field> options = new ArrayList<Field>();
- final List<Field> operands = new ArrayList<Field>();
+ final List<Field> options = new ArrayList<>();
+ final List<Field> operands = new ArrayList<>();
Class<?> cls = command.getClass();
while (cls != null) {
for (final Field field : cls.getDeclaredFields()) {
@@ -3064,12 +3064,12 @@ public class CommandLine {
* @return a detailed synopsis */
public String detailedSynopsis(final int synopsisHeadingLength, final Comparator<Field> optionSort, final boolean clusterBooleanOptions) {
Text optionText = ansi().new Text(0);
- final List<Field> fields = new ArrayList<Field>(optionFields); // iterate in declaration order
+ final List<Field> fields = new ArrayList<>(optionFields); // iterate in declaration order
if (optionSort != null) {
Collections.sort(fields, optionSort);// iterate in specified sort order
}
if (clusterBooleanOptions) { // cluster all short boolean options into a single string
- final List<Field> booleanOptions = new ArrayList<Field>();
+ final List<Field> booleanOptions = new ArrayList<>();
final StringBuilder clusteredRequired = new StringBuilder("-");
final StringBuilder clusteredOptional = new StringBuilder("-");
for (final Field field : fields) {
@@ -3170,7 +3170,7 @@ public class CommandLine {
* @return the fully formatted option list
*/
public String optionList(final Layout layout, final Comparator<Field> optionSort, final IParamLabelRenderer valueLabelRenderer) {
- final List<Field> fields = new ArrayList<Field>(optionFields); // options are stored in order of declaration
+ final List<Field> fields = new ArrayList<>(optionFields); // options are stored in order of declaration
if (optionSort != null) {
Collections.sort(fields, optionSort); // default: sort options ABC
}
@@ -3339,7 +3339,7 @@ public class CommandLine {
return textTable.toString();
}
private static int maxLength(final Collection<String> any) {
- final List<String> strings = new ArrayList<String>(any);
+ final List<String> strings = new ArrayList<>(any);
Collections.sort(strings, Collections.reverseOrder(Help.shortestFirst()));
return strings.get(0).length();
}
@@ -3552,7 +3552,7 @@ public class CommandLine {
final Text longOptionText,
final Object defaultValue) {
final Text EMPTY = Ansi.EMPTY_TEXT;
- final List<Text[]> result = new ArrayList<Text[]>();
+ final List<Text[]> result = new ArrayList<>();
Text[] descriptionFirstLines = scheme.ansi().new Text(str(option.description(), 0)).splitLines();
if (descriptionFirstLines.length == 0) {
if (showDefault) {
@@ -3635,7 +3635,7 @@ public class CommandLine {
final Text requiredParameter = scheme.parameterText(Range.parameterArity(field).min > 0 ? requiredMarker : "");
final Text EMPTY = Ansi.EMPTY_TEXT;
- final List<Text[]> result = new ArrayList<Text[]>();
+ final List<Text[]> result = new ArrayList<>();
Text[] descriptionFirstLines = scheme.ansi().new Text(str(params.description(), 0)).splitLines();
if (descriptionFirstLines.length == 0) { descriptionFirstLines = new Text[]{ EMPTY }; }
result.add(new Text[] { requiredParameter, EMPTY, EMPTY, label, descriptionFirstLines[0] });
@@ -3910,7 +3910,7 @@ public class CommandLine {
public final Column[] columns;
/** The {@code char[]} slots of the {@code TextTable} to copy text values into. */
- protected final List<Text> columnValues = new ArrayList<Text>();
+ protected final List<Text> columnValues = new ArrayList<>();
/** By default, indent wrapped lines by 2 spaces. */
public int indentWrappedLines = 2;
@@ -4157,10 +4157,10 @@ public class CommandLine {
* @see Help#defaultColorScheme(Ansi)
*/
public static class ColorScheme {
- public final List<IStyle> commandStyles = new ArrayList<IStyle>();
- public final List<IStyle> optionStyles = new ArrayList<IStyle>();
- public final List<IStyle> parameterStyles = new ArrayList<IStyle>();
- public final List<IStyle> optionParamStyles = new ArrayList<IStyle>();
+ public final List<IStyle> commandStyles = new ArrayList<>();
+ public final List<IStyle> optionStyles = new ArrayList<>();
+ public final List<IStyle> parameterStyles = new ArrayList<>();
+ public final List<IStyle> optionParamStyles = new ArrayList<>();
private final Ansi ansi;
/** Constructs a new ColorScheme with {@link Help.Ansi#AUTO}. */
@@ -4450,7 +4450,7 @@ public class CommandLine {
private int from;
private int length;
private StringBuilder plain = new StringBuilder();
- private List<StyledSection> sections = new ArrayList<StyledSection>();
+ private List<StyledSection> sections = new ArrayList<>();
/** Constructs a Text with the specified max length (for use in a TextTable Column).
* @param maxLength max length of this text */
@@ -4511,7 +4511,7 @@ public class CommandLine {
}
public Text[] splitLines() {
- final List<Text> result = new ArrayList<Text>();
+ final List<Text> result = new ArrayList<>();
boolean trailingEmptyString = false;
int start = 0, end = 0;
for (int i = 0; i < plain.length(); i++, end = i) {
@@ -4562,7 +4562,7 @@ public class CommandLine {
final Text result = (Text) clone();
result.plain = new StringBuilder(plain.toString().substring(from, from + length));
result.from = 0;
- result.sections = new ArrayList<StyledSection>();
+ result.sections = new ArrayList<>();
for (final StyledSection section : sections) {
result.sections.add(section.withStartIndex(section.startIndex - from));
}
@@ -4765,7 +4765,7 @@ public class CommandLine {
return new MissingParameterException(cmd, "Missing required option '"
+ describe(missing.iterator().next(), separator) + "'");
}
- final List<String> names = new ArrayList<String>(missing.size());
+ final List<String> names = new ArrayList<>(missing.size());
for (final Field field : missing) {
names.add(describe(field, separator));
}
@@ -4802,7 +4802,7 @@ public class CommandLine {
public static class UnmatchedArgumentException extends ParameterException {
private static final long serialVersionUID = -8700426380701452440L;
public UnmatchedArgumentException(final CommandLine commandLine, final String msg) { super(commandLine, msg); }
- public UnmatchedArgumentException(final CommandLine commandLine, final Stack<String> args) { this(commandLine, new ArrayList<String>(reverse(args))); }
+ public UnmatchedArgumentException(final CommandLine commandLine, final Stack<String> args) { this(commandLine, new ArrayList<>(reverse(args))); }
public UnmatchedArgumentException(final CommandLine commandLine, final List<String> args) { this(commandLine, "Unmatched argument" + (args.size() == 1 ? " " : "s ") + args); }
}
/** Exception indicating that more values were specified for an option or parameter than its {@link Option#arity() arity} allows. */
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
index b4aaeab..7536ae8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
@@ -187,12 +187,11 @@ public final class OptionConverter {
+ ":pri=[" + levelName + "]");
try {
- Class customLevel = Loader.loadClass(clazz);
+ Class<?> customLevel = Loader.loadClass(clazz);
// get a ref to the specified class' static method
// toLevel(String, org.apache.log4j.Level)
- Class[] paramTypes = new Class[] { String.class, Level.class
- };
+ Class<?>[] paramTypes = new Class[] { String.class, Level.class };
java.lang.reflect.Method toLevelMethod =
customLevel.getMethod("toLevel", paramTypes);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
index 187a08f..d52120f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
@@ -84,7 +84,7 @@ public abstract class QueueFullAbstractTest {
}
}
- static Stack transform(final List<LogEvent> logEvents) {
+ static Stack<String> transform(final List<LogEvent> logEvents) {
final List<String> filtered = new ArrayList<>(logEvents.size());
for (final LogEvent event : logEvents) {
filtered.add(event.getMessage().getFormattedMessage());
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
index 9c45774..fedba5c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
@@ -32,7 +32,7 @@ public class MainLookupTest {
public void testMainArgs(){
MainMapLookup.setMainArguments("--file", "foo.txt", "--verbose", "-x", "bar");
String str ="${key} ${main:-1} ${main:0} ${main:1} ${main:2} ${main:3} ${main:4} ${main:\\--file} ${main:foo.txt} ${main:\\--verbose} ${main:\\-x} ${main:bar} ${main:\\--quiet:-true}";
- Map<String, String> properties = new HashMap<String, String>();
+ Map<String, String> properties = new HashMap<>();
properties.put("key", "value");
properties.put("bar", "default_bar_value");
Interpolator lookup = new Interpolator(properties);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
index 993db8a..f8a0b9e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
@@ -199,12 +199,12 @@ public class ListAppender extends AbstractAppender {
/** Returns an immutable snapshot of captured log events */
public List<LogEvent> getEvents() {
- return Collections.<LogEvent>unmodifiableList(new ArrayList<LogEvent>(events));
+ return Collections.<LogEvent>unmodifiableList(new ArrayList<>(events));
}
/** Returns an immutable snapshot of captured messages */
public List<String> getMessages() {
- return Collections.<String>unmodifiableList(new ArrayList<String>(messages));
+ return Collections.<String>unmodifiableList(new ArrayList<>(messages));
}
/**
@@ -221,7 +221,7 @@ public class ListAppender extends AbstractAppender {
/** Returns an immutable snapshot of captured data */
public List<byte[]> getData() {
- return Collections.<byte[]>unmodifiableList(new ArrayList<byte[]>(data));
+ return Collections.<byte[]>unmodifiableList(new ArrayList<>(data));
}
public static ListAppender createAppender(final String name, final boolean newLine, final boolean raw,
diff --git a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
index 6225b4c..559c0be 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
@@ -97,10 +97,9 @@ public class LogManager extends java.util.logging.LogManager {
} finally {
activeRequests.remove(name);
}
- } else {
- LOGGER.warn("Recursive call to getLogger for {} ignored.", name);
- return new NoOpLogger(name);
}
+ LOGGER.warn("Recursive call to getLogger for {} ignored.", name);
+ return new NoOpLogger(name);
}
@Override
diff --git a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java
index e414045..a709610 100644
--- a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java
+++ b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java
@@ -53,9 +53,8 @@ public class ContainerUtil {
.findFirst().orElse(null);
LOGGER.debug("Found container id {}", id);
return id;
- } else {
- LOGGER.warn("Unable to access container information");
}
+ LOGGER.warn("Unable to access container information");
} catch (IOException ioe) {
LOGGER.warn("Error obtaining container id: {}", ioe.getMessage());
}
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/DummyRecyclerFactory.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/DummyRecyclerFactory.java
index d2b6f77..2a96d98 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/DummyRecyclerFactory.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/DummyRecyclerFactory.java
@@ -33,7 +33,7 @@ public class DummyRecyclerFactory implements RecyclerFactory {
public <V> Recycler<V> create(
final Supplier<V> supplier,
final Consumer<V> cleaner) {
- return new DummyRecycler<V>(supplier);
+ return new DummyRecycler<>(supplier);
}
}
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/QueueingRecyclerFactory.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/QueueingRecyclerFactory.java
index 7ce41d3..85b04ab 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/QueueingRecyclerFactory.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/QueueingRecyclerFactory.java
@@ -34,7 +34,7 @@ public class QueueingRecyclerFactory implements RecyclerFactory {
final Consumer<V> cleaner) {
@SuppressWarnings("unchecked")
final Queue<V> queue = (Queue<V>) queueSupplier.get();
- return new QueueingRecycler<V>(supplier, cleaner, queue);
+ return new QueueingRecycler<>(supplier, cleaner, queue);
}
}
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ReflectionBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ReflectionBenchmark.java
index 3adb5db..fabbb00 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ReflectionBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ReflectionBenchmark.java
@@ -63,7 +63,7 @@ public class ReflectionBenchmark {
@State(Scope.Benchmark)
public static class ClassContextManager extends SecurityManager {
@Override
- protected Class[] getClassContext() {
+ protected Class<?>[] getClassContext() {
return super.getClassContext();
}
}
@@ -148,9 +148,8 @@ public class ReflectionBenchmark {
private Class<?> findClass(final int depth) {
if (depth == 1) {
return locateCaller();
- } else {
- return findClass(depth - 1);
}
+ return findClass(depth - 1);
}
private Class<?> locateCaller() {
@@ -163,9 +162,8 @@ public class ReflectionBenchmark {
private String findMethodName(final int depth) {
if (depth == 1) {
return locateMethodName();
- } else {
- return findMethodName(depth - 1);
}
+ return findMethodName(depth - 1);
}
private String locateMethodName() {
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
index 5c7f750..05b572a 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
@@ -53,14 +53,14 @@ public class ThreadsafeDateFormatBenchmark {
private final Date date = new Date();
private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
- private final ThreadLocal<SimpleDateFormat> threadLocalSDFormat = new ThreadLocal<SimpleDateFormat>() {
+ private final ThreadLocal<SimpleDateFormat> threadLocalSDFormat = new ThreadLocal<>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("HH:mm:ss.SSS");
}
};
- private final ThreadLocal<FormatterSimple> threadLocalCachedSDFormat = new ThreadLocal<FormatterSimple>() {
+ private final ThreadLocal<FormatterSimple> threadLocalCachedSDFormat = new ThreadLocal<>() {
@Override
protected FormatterSimple initialValue() {
return new FormatterSimple();
@@ -113,7 +113,7 @@ public class ThreadsafeDateFormatBenchmark {
private final FixedDateFormat customFormat = FixedDateFormat.createIfSupported("HH:mm:ss.SSS");
private long timestamp;
private String formatted;
- private final ThreadLocal<char[]> reusableBuffer = new ThreadLocal<char[]>() {
+ private final ThreadLocal<char[]> reusableBuffer = new ThreadLocal<>() {
@Override
protected char[] initialValue() {
return new char[255];
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
index 6ae0a8d..239d201 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
@@ -49,7 +49,7 @@ import org.openjdk.jmh.annotations.State;
@State(Scope.Benchmark)
public class TimeFormatBenchmark {
- ThreadLocal<SimpleDateFormat> threadLocalSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
+ ThreadLocal<SimpleDateFormat> threadLocalSimpleDateFormat = new ThreadLocal<>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("HH:mm:ss.SSS");
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/util/StackDriver.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/util/StackDriver.java
index 9f239e4..08184b7 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/util/StackDriver.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/util/StackDriver.java
@@ -27,9 +27,8 @@ public class StackDriver {
if (--initialDepth == 0) {
Processor processor = new Processor();
return processor.apply(targetDepth, supplier);
- } else {
- return deepCall(initialDepth, targetDepth, supplier);
}
+ return deepCall(initialDepth, targetDepth, supplier);
}
public static class Processor implements BiFunction<Integer, Function<String, StackTraceElement>, StackTraceElement> {
@@ -39,9 +38,8 @@ public class StackDriver {
public StackTraceElement apply(Integer depth, Function<String, StackTraceElement> function) {
if (--depth == 0) {
return function.apply(FQCN);
- } else {
- return apply(depth, function);
}
+ return apply(depth, function);
}
}
}
diff --git a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java
index be17a5b..2ebe9ce 100644
--- a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java
+++ b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java
@@ -199,9 +199,8 @@ public class Log4j2CloudConfigLoggingSystem extends Log4J2LoggingSystem {
try {
if (file != null) {
return new ConfigurationSource(urlConnection.getInputStream(), FileUtils.fileFromUri(url.toURI()));
- } else {
- return new ConfigurationSource(urlConnection.getInputStream(), url, urlConnection.getLastModified());
}
+ return new ConfigurationSource(urlConnection.getInputStream(), url, urlConnection.getLastModified());
} catch (FileNotFoundException ex) {
LOGGER.info("Unable to locate file {}, ignoring.", url.toString());
return null;
diff --git a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringLookup.java b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringLookup.java
index 513aaaf..4e2d528 100644
--- a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringLookup.java
+++ b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringLookup.java
@@ -63,25 +63,23 @@ public class SpringLookup extends SpringEnvironmentHolder implements StrLookup {
int index = Integer.parseInt(matcher.group(1));
if (index < env.getActiveProfiles().length) {
return env.getActiveProfiles()[index];
- } else {
- LOGGER.warn("Index out of bounds for Spring active profiles: {}", index);
- return null;
}
+ LOGGER.warn("Index out of bounds for Spring active profiles: {}", index);
+ return null;
} catch (Exception ex) {
LOGGER.warn("Unable to parse {} as integer value", matcher.group(1));
return null;
}
- } else {
- StringBuilder sb = new StringBuilder();
- for (String profile : env.getActiveProfiles()) {
- if (sb.length() > 0) {
- sb.append(",");
- }
- sb.append(profile);
+ }
+ StringBuilder sb = new StringBuilder();
+ for (String profile : env.getActiveProfiles()) {
+ if (sb.length() > 0) {
+ sb.append(",");
}
- return sb.toString();
+ sb.append(profile);
}
+ return sb.toString();
}
}
} else if (lowerKey.startsWith(DEFAULT)) {
@@ -99,25 +97,23 @@ public class SpringLookup extends SpringEnvironmentHolder implements StrLookup {
int index = Integer.parseInt(matcher.group(1));
if (index < env.getDefaultProfiles().length) {
return env.getDefaultProfiles()[index];
- } else {
- LOGGER.warn("Index out of bounds for Spring default profiles: {}", index);
- return null;
}
+ LOGGER.warn("Index out of bounds for Spring default profiles: {}", index);
+ return null;
} catch (Exception ex) {
LOGGER.warn("Unable to parse {} as integer value", matcher.group(1));
return null;
}
- } else {
- StringBuilder sb = new StringBuilder();
- for (String profile : env.getDefaultProfiles()) {
- if (sb.length() > 0) {
- sb.append(",");
- }
- sb.append(profile);
+ }
+ StringBuilder sb = new StringBuilder();
+ for (String profile : env.getDefaultProfiles()) {
+ if (sb.length() > 0) {
+ sb.append(",");
}
- return sb.toString();
+ sb.append(profile);
}
+ return sb.toString();
}
}
}