Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-3956: [Java] Fix NPE in Protocol#equals #2791

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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