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

OptionalDouble.empty().hashCode() doesn't return zero

XMLWordPrintable

      The spec for OptionalDouble.hashCode() says:

           * Returns the hash code value of the present value, if any, or 0 (zero) if
           * no value is present.

      However it doesn't happen with JDK8b82-lambda:

      --------------------------------------------------
      import java.util.OptionalDouble;
      import java.util.OptionalInt;
      import java.util.OptionalLong;

      public class EmptyOptionalDoubleHashCode {

          public static void main(String[] args) {
              System.out.println("OptionalInt.empty().hashCode() = " + OptionalInt.empty().hashCode());
              System.out.println("OptionalLong.empty().hashCode() = " + OptionalLong.empty().hashCode());
              System.out.println("OptionalDouble.empty().hashCode() = " + OptionalDouble.empty().hashCode());
          }
      }
      --------------------------------------------------

      The output is:

      OptionalInt.empty().hashCode() = 0
      OptionalLong.empty().hashCode() = 0
      OptionalDouble.empty().hashCode() = 2146959360

      The following JCK test fails due to this issue:
      api/java_util/OptionalDouble/index.html#General[hashCodeEmptyZeroValue]


            mduigou Mike Duigou
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: