Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-6673

Segment and Stamped implement Comparable, but don't override equals.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.0.0
    • streams
    • None

    Description

      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:

      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().

       

      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.

      Attachments

        1. KAFKA_6673.patch
          1 kB
          Asutosh Pandya

        Activity

          People

            asutosh_pandya Asutosh Pandya
            KoenDG Koen De Groote
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: