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

SimpleTimeZone equals() Returns True for Unequal Instances with Different hashCode Values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • 26
    • 8, 11, 17, 21, 24, 25
    • core-libs
    • Cause Known
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      If two objects are equal according to their equals(Object) method, then calling hashCode() on each of the two objects must produce the same integer result. However, Two SimpleTimeZone are equal but within different hashcode.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Junit testcase

      ACTUAL -
      95 0
      true
      java.lang.AssertionError: Contract failed: equals-hashcode on simpleTimeZone2 and simpleTimeZone7

      ---------- BEGIN SOURCE ----------
          @Test
          public void test03() throws Throwable {
              java.util.SimpleTimeZone simpleTimeZone2 = new java.util.SimpleTimeZone( 0, "hi!");
              simpleTimeZone2.setStartYear( -1);
              java.util.SimpleTimeZone simpleTimeZone7 = new java.util.SimpleTimeZone( 0, "hi!");
              simpleTimeZone7.setStartYear( -1);
              simpleTimeZone2.setEndRule(10, 0, (int) '4', (int) 'a');
              System.out.println(simpleTimeZone2.hashCode() + " " + simpleTimeZone7.hashCode());
              System.out.println(simpleTimeZone2.equals(simpleTimeZone7));
              org.junit.Assert.assertTrue("Contract failed: equals-hashcode on simpleTimeZone2 and simpleTimeZone7", simpleTimeZone2.equals(simpleTimeZone7) ? simpleTimeZone2.hashCode() == simpleTimeZone7.hashCode() : true);
          }
      ---------- END SOURCE ----------

            naoto Naoto Sato
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: