diff --git a/client/src/com/aerospike/client/Value.java b/client/src/com/aerospike/client/Value.java index 0dc598846..2940c03d3 100644 --- a/client/src/com/aerospike/client/Value.java +++ b/client/src/com/aerospike/client/Value.java @@ -753,9 +753,21 @@ public String toString() { @Override public boolean equals(Object other) { - return (other != null && - this.getClass().equals(other.getClass()) && - this.value.equals(((StringValue)other).value)); + // Fast path: same reference + if (this == other) { + return true; + } + // Null check + if (other == null) { + return false; + } + // Ensure exact same runtime class (preserve original semantics) + if (this.getClass() != other.getClass()) { + return false; + } + // Safe cast and value comparison + StringValue o = (StringValue) other; + return this.value.equals(o.value); } @Override