diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/AWSLogReference.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/AWSLogReference.java index 365b1821..13373514 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/AWSLogReference.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/AWSLogReference.java @@ -63,11 +63,11 @@ public boolean equals(Object o) { */ public int hashCode() { if (arn == null && logGroup == null) { - return Objects.hash(""); + return "".hashCode(); } else if (arn == null) { - return Objects.hash(logGroup); + return logGroup.hashCode(); } else { - return Objects.hash(arn); + return arn.hashCode(); } } } diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/TraceID.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/TraceID.java index 0b3137fd..96ba8bb0 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/TraceID.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/TraceID.java @@ -2,6 +2,7 @@ import java.math.BigInteger; import java.time.Instant; +import java.util.Objects; import com.amazonaws.xray.ThreadLocalStorage; @@ -85,18 +86,10 @@ public int hashCode() { public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) + if (!(obj instanceof TraceID)) { return false; + } TraceID other = (TraceID) obj; - if (number == null) { - if (other.number != null) - return false; - } else if (!number.equals(other.number)) - return false; - if (startTime != other.startTime) - return false; - return true; + return Objects.equals(number, other.number) && startTime == other.startTime; } } diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EC2Plugin.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EC2Plugin.java index e30fe7ca..ec556356 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EC2Plugin.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EC2Plugin.java @@ -8,7 +8,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import com.amazonaws.xray.entities.AWSLogReference; @@ -155,6 +154,6 @@ public boolean equals(Object o) { * Hash plugin object using origin to uniquely identify them */ public int hashCode() { - return Objects.hash(this.getOrigin()); + return this.getOrigin().hashCode(); } } diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ECSPlugin.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ECSPlugin.java index 59d77059..425d705a 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ECSPlugin.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ECSPlugin.java @@ -5,7 +5,6 @@ import java.net.UnknownHostException; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import com.amazonaws.xray.utils.DockerUtils; import org.apache.commons.logging.Log; @@ -90,7 +89,7 @@ public boolean equals(Object o) { * Hash plugin object using origin to uniquely identify them */ public int hashCode() { - return Objects.hash(this.getOrigin()); + return this.getOrigin().hashCode(); } diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EKSPlugin.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EKSPlugin.java index 343ff971..4afa3b9b 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EKSPlugin.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/EKSPlugin.java @@ -8,12 +8,10 @@ import java.io.IOException; import java.net.InetAddress; -import java.net.MalformedURLException; import java.net.UnknownHostException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.Objects; import java.util.Set; @@ -133,6 +131,6 @@ public boolean equals(Object o) { * Hash plugin object using origin to uniquely identify them */ public int hashCode() { - return Objects.hash(this.getOrigin()); + return this.getOrigin().hashCode(); } } diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ElasticBeanstalkPlugin.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ElasticBeanstalkPlugin.java index 2349b389..db71ecbd 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ElasticBeanstalkPlugin.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/ElasticBeanstalkPlugin.java @@ -5,7 +5,6 @@ import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -90,6 +89,6 @@ public boolean equals(Object o) { * Hash plugin object using origin to uniquely identify them */ public int hashCode() { - return Objects.hash(this.getOrigin()); + return this.getOrigin().hashCode(); } } diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRule.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRule.java index 0471bc8e..d0120fdb 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRule.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRule.java @@ -12,6 +12,7 @@ import java.time.Instant; import java.util.Date; +import java.util.Objects; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -240,7 +241,9 @@ public String getName() { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof CentralizedRule)) { + return false; + } CentralizedRule that = (CentralizedRule) o; @@ -249,7 +252,7 @@ public boolean equals(Object o) { if (!name.equals(that.name)) return false; if (!centralizedReservoir.equals(that.centralizedReservoir)) return false; if (!statistics.equals(that.statistics)) return false; - return matchers != null ? matchers.equals(that.matchers) : that.matchers == null; + return Objects.equals(matchers, that.matchers); } @Override