title: Java hashCode() differs in different executions of same object creation
body: <p><strong>Basic information:</strong>
  I have a MyCustomObjectGenerator that generates MyCustomObject . This object (should be) is always created with identical values. This object contains mutch code, interfaces, enums, sub-classes ..., so I keep it simple here. All objects or implementations of interfaces override the equals &amp; hashCode method (hopefully in a correct way). </p>
  
  <p>This MyCustomObject is serialized to JSON with Jackson with custom serializers (MyCustomObject does not contain any Jackson dependencies like Jackson annotations!). </p>
  
  <p>Each JSON gets an ID calculated based on the hashCode of MyCustomObject (see code below). This id is just used as checksum to identify same jsons very fast. There is another ID based on UUID, that identifies the job itself, so I know that 2 jobs can have the same checksum!</p>
  
  <p><strong>The problem:</strong>
  There are two JUnit-Tests (minimal &amp; maximal method in one Junit-Testclass), that generate a JSON and check this JSON with a predefined JSON from File. If I run both tests/methods the JSON matches with the one from the file, but if i just run the testMaximal() method the assertion fails, due to the fact that the generated id is not the same. So the hashCode seems to differ. If I start the two test-methods again, jsons match again with the one from file , so the generated object does not contain any random content like <em>ZonedDateTime.now()</em>. The other JSON values are always the same, only the ID differs. The HashCode seems to be the same if the execution (2 methods/1 method) condition is the same, but differs if this execution condition is changed. This is really strange for me.</p>
  
  <p>Now I have to evaluate, what class does not correctly override(or produces different hashCode) the hashCode method (the id is based on hashCodes of all contained objects). Does someone have any good idea to print the hashCode of each object, variable, subclass, interface ... of MyCustomObject via Reflection?  I already tried</p>
  
  <pre><code>ReflectionToStringBuilder.toString(myCustomObject, ToStringStyle.DEFAULT_STYLE)
  </code></pre>
  
  <p>but this does not print the hashCode of each sub-sub-element of myCustomObject.</p>
  
  <p>If I could print the exact object values incl. hashValue, then I could compare it. </p>
  
  <p>I already found one object that differs with ReflectionToStringBuilder.toString(), but this object itself contains mutch interface,variables and so on, but all values in this BlablaObject@4fb64261[...] are the same, and there the hashCode is missing</p>
  
  <p><strong>On top question:</strong>
  Are there known cases, that hashCode() behaves strange like "If you use enum as key in a HashMap, then hashCode depends on java stack or JVM version" or sth. like that.</p>
  
  <hr>
  
  <p><strong>CODE</strong></p>
  
  <p><strong>MyCustomObjectGenerator .java</strong></p>
  
  <pre><code>    public class MyCustomObjectGenerator {
  
      private MyCustomObject(){};
  
      public static MyCustomObject generate(boolean isMinimal){
          //if minimal then create minimal object
          //if minimal == false then create maximized object**strong text**
          MyCustomObject myCustomObject = new MyCustomObject(...);
          myCustomObject.setXY(...)
          ...
          return myCustomObject;
      }
  }
  </code></pre>
  
  <p><strong>MyCustomObject.java</strong></p>
  
  <pre><code>import javax.xml.bind.DatatypeConverter;
  import java.io.UnsupportedEncodingException;
  import java.security.MessageDigest;
  import java.security.NoSuchAlgorithmException;
  import org.apache.commons.lang3.builder.HashCodeBuilder;
  import org.apache.commons.lang3.builder.EqualsBuilder;
  
  public class MyCustomObject {
      //variables, enums, interface ... here
      ...    
      public MyCustomObject(...){...}
  
      //mutch code here
      ...
  
      public String getChecksum() {
          String id = Integer.toString(hashCode());
          try {
              MessageDigest md = MessageDigest.getInstance("MD5");
              byte[] digest = md.digest(id.getBytes("UTF-8"));
              id = DatatypeConverter.printHexBinary(digest);
          } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
              // do nothing here
          }
          return new id;
      }
  
      @Override
      public int hashCode() {
          return new HashCodeBuilder(-1013166723, 372138085)
          //if needed in extended classes: .appendSuper(super.hashCode())
          .append(...)
          ....
          .toHashCode();
      }
  
      @Override
      public boolean equals(
              final Object other) {
          if (!(other instanceof MyCustomObject)) {
              return false;
          }
          MyCustomObject castOther = (MyCustomObject) other;
          return new EqualsBuilder()
              // if needed in extended classes: .appendSuper(super.hashCode())
              .append(..., ...)
              ....
              .isEquals();
      }
  }
  </code></pre>