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
commit f73102f7b79afa05633a272a984e093e437a7aac Author: Gary Gregory <[email protected]> AuthorDate: Thu Nov 12 16:38:24 2020 -0500 Use Objects.equals(). --- .../log4j/core/appender/TlsSyslogFrame.java | 7 ++---- .../log4j/core/filter/DynamicThresholdFilter.java | 18 +++------------- .../logging/log4j/core/impl/ExtendedClassInfo.java | 13 +++-------- .../log4j/core/impl/ExtendedStackTraceElement.java | 13 +++-------- .../logging/log4j/core/impl/ThrowableProxy.java | 13 +++-------- .../logging/log4j/core/layout/PatternMatch.java | 13 +++-------- .../net/ssl/AbstractKeyStoreConfiguration.java | 13 +++-------- .../log4j/core/net/ssl/KeyStoreConfiguration.java | 7 ++---- .../log4j/core/net/ssl/SslConfiguration.java | 25 +++++----------------- .../log4j/core/net/ssl/StoreConfiguration.java | 6 +----- .../core/net/ssl/TrustStoreConfiguration.java | 7 ++---- .../logging/log4j/core/util/KeyValuePair.java | 14 ++++-------- .../logging/log4j/core/jackson/LevelMixInTest.java | 7 ++---- .../java/org/apache/logging/slf4j/Log4jMarker.java | 7 ++---- .../java/org/apache/logging/slf4j/Log4jMarker.java | 7 ++---- 15 files changed, 40 insertions(+), 130 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TlsSyslogFrame.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TlsSyslogFrame.java index 27e90cd..9b508d8 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TlsSyslogFrame.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/TlsSyslogFrame.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.appender; import java.nio.charset.StandardCharsets; +import java.util.Objects; import org.apache.logging.log4j.util.Chars; @@ -64,11 +65,7 @@ public class TlsSyslogFrame { return false; } final TlsSyslogFrame other = (TlsSyslogFrame) obj; - if (message == null) { - if (other.message != null) { - return false; - } - } else if (!message.equals(other.message)) { + if (!Objects.equals(message, other.message)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java index 923a39c..5a12aef 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java @@ -98,25 +98,13 @@ public final class DynamicThresholdFilter extends AbstractFilter { return false; } final DynamicThresholdFilter other = (DynamicThresholdFilter) obj; - if (defaultThreshold == null) { - if (other.defaultThreshold != null) { - return false; - } - } else if (!defaultThreshold.equals(other.defaultThreshold)) { + if (!Objects.equals(defaultThreshold, other.defaultThreshold)) { return false; } - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { + if (!Objects.equals(key, other.key)) { return false; } - if (levelMap == null) { - if (other.levelMap != null) { - return false; - } - } else if (!levelMap.equals(other.levelMap)) { + if (!Objects.equals(levelMap, other.levelMap)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java index 2be5f5c..086dbbd 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.impl; import java.io.Serializable; +import java.util.Objects; import org.apache.logging.log4j.core.pattern.PlainTextRenderer; import org.apache.logging.log4j.core.pattern.TextRenderer; @@ -63,18 +64,10 @@ public final class ExtendedClassInfo implements Serializable { if (this.exact != other.exact) { return false; } - if (this.location == null) { - if (other.location != null) { - return false; - } - } else if (!this.location.equals(other.location)) { + if (!Objects.equals(this.location, other.location)) { return false; } - if (this.version == null) { - if (other.version != null) { - return false; - } - } else if (!this.version.equals(other.version)) { + if (!Objects.equals(this.version, other.version)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java index 06183e4..255278d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.impl; import java.io.Serializable; +import java.util.Objects; import org.apache.logging.log4j.core.pattern.PlainTextRenderer; import org.apache.logging.log4j.core.pattern.TextRenderer; @@ -67,18 +68,10 @@ public final class ExtendedStackTraceElement implements Serializable { return false; } final ExtendedStackTraceElement other = (ExtendedStackTraceElement) obj; - if (this.extraClassInfo == null) { - if (other.extraClassInfo != null) { - return false; - } - } else if (!this.extraClassInfo.equals(other.extraClassInfo)) { + if (!Objects.equals(this.extraClassInfo, other.extraClassInfo)) { return false; } - if (this.stackTraceElement == null) { - if (other.stackTraceElement != null) { - return false; - } - } else if (!this.stackTraceElement.equals(other.stackTraceElement)) { + if (!Objects.equals(this.stackTraceElement, other.stackTraceElement)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java index 1c043af..c3ed31d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.Stack; @@ -152,21 +153,13 @@ public class ThrowableProxy implements Serializable { return false; } final ThrowableProxy other = (ThrowableProxy) obj; - if (this.causeProxy == null) { - if (other.causeProxy != null) { - return false; - } - } else if (!this.causeProxy.equals(other.causeProxy)) { + if (!Objects.equals(this.causeProxy, other.causeProxy)) { return false; } if (this.commonElementCount != other.commonElementCount) { return false; } - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { + if (!Objects.equals(this.name, other.name)) { return false; } if (!Arrays.equals(this.extendedStackTrace, other.extendedStackTrace)) { diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternMatch.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternMatch.java index 2c6803d..c7f3b68 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternMatch.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternMatch.java @@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.layout; import java.io.ObjectStreamException; import java.io.Serializable; +import java.util.Objects; import org.apache.logging.log4j.core.config.Node; import org.apache.logging.log4j.core.config.plugins.Plugin; @@ -123,18 +124,10 @@ public final class PatternMatch { return false; } final PatternMatch other = (PatternMatch) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { + if (!Objects.equals(key, other.key)) { return false; } - if (pattern == null) { - if (other.pattern != null) { - return false; - } - } else if (!pattern.equals(other.pattern)) { + if (!Objects.equals(pattern, other.pattern)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java index 27ab29d..a79a657 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/AbstractKeyStoreConfiguration.java @@ -24,6 +24,7 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.util.Arrays; +import java.util.Objects; import org.apache.logging.log4j.core.config.ConfigurationSource; import org.apache.logging.log4j.core.util.NetUtils; @@ -128,18 +129,10 @@ public class AbstractKeyStoreConfiguration extends StoreConfiguration<KeyStore> return false; } final AbstractKeyStoreConfiguration other = (AbstractKeyStoreConfiguration) obj; - if (keyStore == null) { - if (other.keyStore != null) { - return false; - } - } else if (!keyStore.equals(other.keyStore)) { + if (!Objects.equals(keyStore, other.keyStore)) { return false; } - if (keyStoreType == null) { - if (other.keyStoreType != null) { - return false; - } - } else if (!keyStoreType.equals(other.keyStoreType)) { + if (!Objects.equals(keyStoreType, other.keyStoreType)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java index ff479be..edd2554 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java @@ -20,6 +20,7 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.util.Arrays; +import java.util.Objects; import javax.net.ssl.KeyManagerFactory; @@ -197,11 +198,7 @@ public class KeyStoreConfiguration extends AbstractKeyStoreConfiguration { return false; } final KeyStoreConfiguration other = (KeyStoreConfiguration) obj; - if (keyManagerFactoryAlgorithm == null) { - if (other.keyManagerFactoryAlgorithm != null) { - return false; - } - } else if (!keyManagerFactoryAlgorithm.equals(other.keyManagerFactoryAlgorithm)) { + if (!Objects.equals(keyManagerFactoryAlgorithm, other.keyManagerFactoryAlgorithm)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java index e6df7ff..1b10a37 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java @@ -20,6 +20,7 @@ import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; +import java.util.Objects; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; @@ -280,32 +281,16 @@ public class SslConfiguration { return false; } final SslConfiguration other = (SslConfiguration) obj; - if (keyStoreConfig == null) { - if (other.keyStoreConfig != null) { - return false; - } - } else if (!keyStoreConfig.equals(other.keyStoreConfig)) { + if (!Objects.equals(keyStoreConfig, other.keyStoreConfig)) { return false; } - if (protocol == null) { - if (other.protocol != null) { - return false; - } - } else if (!protocol.equals(other.protocol)) { + if (!Objects.equals(protocol, other.protocol)) { return false; } - if (sslContext == null) { - if (other.sslContext != null) { - return false; - } - } else if (!sslContext.equals(other.sslContext)) { + if (!Objects.equals(sslContext, other.sslContext)) { return false; } - if (trustStoreConfig == null) { - if (other.trustStoreConfig != null) { - return false; - } - } else if (!trustStoreConfig.equals(other.trustStoreConfig)) { + if (!Objects.equals(trustStoreConfig, other.trustStoreConfig)) { return false; } return true; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java index 9bdeaf5..6d4e686 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/StoreConfiguration.java @@ -121,11 +121,7 @@ public class StoreConfiguration<T> { return false; } final StoreConfiguration<?> other = (StoreConfiguration<?>) obj; - if (location == null) { - if (other.location != null) { - return false; - } - } else if (!location.equals(other.location)) { + if (!Objects.equals(location, other.location)) { return false; } if (!Arrays.equals(passwordProvider.getPassword(), other.passwordProvider.getPassword())) { diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java index 08ddc69..06188f8 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java @@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.net.ssl; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import java.util.Objects; import javax.net.ssl.TrustManagerFactory; @@ -177,11 +178,7 @@ public class TrustStoreConfiguration extends AbstractKeyStoreConfiguration { return false; } final TrustStoreConfiguration other = (TrustStoreConfiguration) obj; - if (trustManagerFactoryAlgorithm == null) { - if (other.trustManagerFactoryAlgorithm != null) { - return false; - } - } else if (!trustManagerFactoryAlgorithm.equals(other.trustManagerFactoryAlgorithm)) { + if (!Objects.equals(trustManagerFactoryAlgorithm, other.trustManagerFactoryAlgorithm)) { return false; } return true; 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 6eae7de..93795da 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 @@ -17,6 +17,8 @@ package org.apache.logging.log4j.core.util; +import java.util.Objects; + import org.apache.logging.log4j.core.config.Node; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; @@ -115,18 +117,10 @@ public final class KeyValuePair { return false; } final KeyValuePair other = (KeyValuePair) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { + if (!Objects.equals(key, other.key)) { return false; } - if (value == null) { - if (other.value != null) { - return false; - } - } else if (!value.equals(other.value)) { + if (!Objects.equals(value, other.value)) { return false; } return true; diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInTest.java index acff4b4..53471b6 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInTest.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.jackson; import java.io.IOException; +import java.util.Objects; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.categories.Layouts; @@ -52,11 +53,7 @@ public abstract class LevelMixInTest { return false; } final Fixture other = (Fixture) obj; - if (this.level == null) { - if (other.level != null) { - return false; - } - } else if (!this.level.equals(other.level)) { + if (!Objects.equals(this.level, other.level)) { return false; } return true; diff --git a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java index f0c5b6c..a6e46c5 100644 --- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java +++ b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java @@ -19,6 +19,7 @@ package org.apache.logging.slf4j; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.apache.logging.log4j.MarkerManager; import org.slf4j.IMarkerFactory; @@ -78,11 +79,7 @@ public class Log4jMarker implements Marker { return false; } final Log4jMarker other = (Log4jMarker) obj; - if (marker == null) { - if (other.marker != null) { - return false; - } - } else if (!marker.equals(other.marker)) { + if (!Objects.equals(marker, other.marker)) { return false; } return true; diff --git a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java index 00351f9..c0cb4a0 100644 --- a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java +++ b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java @@ -19,6 +19,7 @@ package org.apache.logging.slf4j; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.apache.logging.log4j.MarkerManager; import org.slf4j.IMarkerFactory; @@ -78,11 +79,7 @@ class Log4jMarker implements Marker { return false; } final Log4jMarker other = (Log4jMarker) obj; - if (marker == null) { - if (other.marker != null) { - return false; - } - } else if (!marker.equals(other.marker)) { + if (!Objects.equals(marker, other.marker)) { return false; } return true;
