Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Duplicate Issue
    • Affects Version/s: 4.0.2.000
    • Fix Version/s: None
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      <cfscript>
      one = "tahi";
      two = "rua";
      three = "toru";

      st1=

      {one=one, two="rua", three=three}

      ;
      st2 = structNew();
      st2.three = st1.three;
      st2.two = two;
      st2.one = "tahi";

      writeOutput("st1.equals(st2): #st1.equals(st2)#<br />");
      writeOutput("st2.equals(st1): #st2.equals(st1)#<br />");
      writeOutput("st1.hashCode(): #st1.hashcode()#<br />");
      writeOutput("st2.hashCode(): #st2.hashcode()#<br />");
      </cfscript>

      Output:
      st1.equals(st2): true
      st2.equals(st1): true
      st1.hashCode(): 18796902 <---
      st2.hashCode(): 4565548 <--- these two should be the same

      Show
      <cfscript> one = "tahi"; two = "rua"; three = "toru"; st1= {one=one, two="rua", three=three} ; st2 = structNew(); st2.three = st1.three; st2.two = two; st2.one = "tahi"; writeOutput("st1.equals(st2): #st1.equals(st2)#<br />"); writeOutput("st2.equals(st1): #st2.equals(st1)#<br />"); writeOutput("st1.hashCode(): #st1.hashcode()#<br />"); writeOutput("st2.hashCode(): #st2.hashcode()#<br />"); </cfscript> Output: st1.equals(st2): true st2.equals(st1): true st1.hashCode(): 18796902 <--- st2.hashCode(): 4565548 <--- these two should be the same

      Description

      See thread on the mailing list: https://groups.google.com/d/topic/railo/ghcIzA50IwI/discussion

      Summary:
      OK, so according to this, the two objects do equal each other, however the hashCodes are different. This is illegal according to how hashCode() & equals() are supposed to be implemented?

      [...]

      Ref: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#hashCode%28%29
      Extract: "If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result."

      [...]

      For the purposes of the fix, despite the spec saying "This integer need not remain consistent from one execution of an application to another execution of the same application" it would be handy if it did stay the same, so if everything else is equal (like there's no performance degradation, or the code would just be unfeasibly complex to write), would it be possible for the hashCode() method to... err... "coincidentally" return the same result for the "same" struct each time? CF manages to achieve this (even across CF versions), but who knows what shenanigans they get up to to effect it.

      Cheers.


      Adam

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                micstriit Michael Offner
                Reporter:
                adamcameroncf Adam Cameron
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: