kafka-jira mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koen De Groote (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KAFKA-6673) Segment and Stamped implement Comparable, but don't override equals.
Date Thu, 22 Mar 2018 08:31:00 GMT

    [ https://issues.apache.org/jira/browse/KAFKA-6673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16409214#comment-16409214
] 

Koen De Groote commented on KAFKA-6673:
---------------------------------------

That implementation would just do an identity comparison. Because Stamped and Segment don't
have an explicit super class, just Object.

And Object's equals is this:

public boolean equals(Object obj) {
    return (this == obj);
}

The whole idea behind this is that the equals method should act logically the same as the
compareTo method, as to have only 1 kind of behavior.

> Segment and Stamped implement Comparable, but don't override equals.
> --------------------------------------------------------------------
>
>                 Key: KAFKA-6673
>                 URL: https://issues.apache.org/jira/browse/KAFKA-6673
>             Project: Kafka
>          Issue Type: Improvement
>          Components: streams
>            Reporter: Koen De Groote
>            Priority: Minor
>         Attachments: KAFKA_6673.patch
>
>
> The classes in question:
> https://github.com/apache/kafka/blob/trunk/streams/src/main/java/org/apache/kafka/streams/state/internals/Segment.java
> and
> https://github.com/apache/kafka/blob/trunk/streams/src/main/java/org/apache/kafka/streams/processor/internals/Stamped.java
> This came up while doing static analysis on the codebase on the trunk branch.
> As described by the analysis tool built into Intellij:
> {quote}
> Reports classes which implement java.lang.Comparable which do not override equals().
If equals() is not overridden, the equals() implementation is not consistent with the compareTo()
implementation. If an object of such a class is added to a collection such as java.util.SortedSet,
this collection will violate the contract of java.util.Set, which is defined in terms of equals().
> {quote}
>  
> Implementing an equals for an object is generally a best practice, especially considering
this caveat, where it's not the compareTo that will be used but the equals method.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message