Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8336036

Synthetic documentation for a record's equals is incorrect for floating-point types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 24
    • 23, 24
    • tools

        (As discovered by my colleague Chris Povirk)

        In the following example, a record with double components implements equals() using Double.compare, as required by JLS 8.10.3.

        However the javadoc for equals for a record incorrectly states that

        > All components in this record class are compared with '=='.

        The javadoc should be updated to reflect the specified behaviour for double and float record components.

        ```
        public record RecordDoubleComponent(double x) {
          public static void main(String[] args) {
            double a = 0.0;
            double b = -0.0;
            System.out.println(a == b);
            System.out.println(new RecordDoubleComponent(a).equals(new RecordDoubleComponent(b)));
          }
        }
        ```

        $ java -fullversion
        openjdk full version "24-ea+5-515"
        $ java RecordDoubleComponent.java
        true
        false
        $ javadoc RecordDoubleComponent.java
        $ grep 'All comp' RecordDoubleComponent.html
        <div class="block">Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.</div>

              liach Chen Liang
              cushon Liam Miller-Cushon
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: