Skip to content

Commit

Permalink
AVRO-3956: [Java] Fix NPE in Protocol#equals (#2791)
Browse files Browse the repository at this point in the history
* Fix NPE in Protocol#equals

* Better Protocol#hashCode
  • Loading branch information
mitasov-ra committed Mar 19, 2024
1 parent 828b600 commit dad0d20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -334,7 +335,7 @@ int propsHashCode() {
}

boolean propsEqual(JsonProperties np) {
return props.equals(np.props);
return Objects.equals(props, np.props);
}

public boolean hasProps() {
Expand Down
8 changes: 5 additions & 3 deletions lang/java/avro/src/main/java/org/apache/avro/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -390,13 +391,14 @@ public boolean equals(Object o) {
if (!(o instanceof Protocol))
return false;
Protocol that = (Protocol) o;
return this.name.equals(that.name) && this.namespace.equals(that.namespace) && this.types.equals(that.types)
&& this.messages.equals(that.messages) && this.propsEqual(that);
return Objects.equals(this.name, that.name) && Objects.equals(this.namespace, that.namespace)
&& Objects.equals(this.types, that.types) && Objects.equals(this.messages, that.messages)
&& this.propsEqual(that);
}

@Override
public int hashCode() {
return name.hashCode() + namespace.hashCode() + types.hashCode() + messages.hashCode() + propsHashCode();
return 31 * Objects.hash(name, namespace, types, messages) + propsHashCode();
}

/** Render this as <a href="https://json.org/">JSON</a>. */
Expand Down

0 comments on commit dad0d20

Please sign in to comment.