title: Spring + Thymeleaf binding form NullpointerException
body: <p>I'm currently working on an user edit form.</p>
  
  <p>I have a user object with the following structure (pseudo code):</p>
  
  <pre><code>User
  
  String name,
  int age,
  Address adress,
  Email email,
  User child,
  
  getter/setter
  </code></pre>
  
  <p>Now, this object i put in as object in a <code>Model</code> like the following:</p>
  
  <pre><code>@RequestMapping(value = "/{login}/edit", method = RequestMethod.GET)
  public ModelAndView editUserByLogin(@PathVariable("login") final String login) {
      final User currentUser = UserRepository.findPersonByLogin(login);
  
      ModelAndView mav = new ModelAndView(URL_EDIT_USER);
      mav.addObject(MODEL_USER, currentUser);
  
      return mav;
  }
  </code></pre>
  
  <p>in my template (i use thymeleaf) i bind these object like this:</p>
  
  <pre><code>&lt;form class="form-horizontal" method="post" &gt;
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label" th:text="#{user.name}"&gt;name&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;input type="text" class="form-control" th:field="*{user.name}" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label" th:text="#{user.address.street}"&gt;name&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;input type="text" class="form-control" th:field="*{user.address.street}" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label" th:text="#{user.child.email.value}"&gt;name&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;input type="text" class="form-control" th:field="*{user.child.email.value}" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label" th:text="#{user.child.address.street}"&gt;name&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;input type="text" class="form-control" th:field="*{user.child.address.street}" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In the GET-Method the template/html shows the correct data i expected. Now i edit the fields and submit the form, then i get the following error:</p>
  
  <pre><code>java.lang.NullPointerException: null
      at com.example.user.model.Email.hashCode(EMail.java:66) ~[classes/:na]
      at java.lang.Object.toString(Unknown Source) ~[na:1.8.0_25]
      at java.lang.String.valueOf(Unknown Source) ~[na:1.8.0_25]
      at java.lang.StringBuilder.append(Unknown Source) ~[na:1.8.0_25]
      at org.springframework.validation.FieldError.toString(FieldError.java:102) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
      at java.lang.String.valueOf(Unknown Source) ~[na:1.8.0_25]
      at java.lang.StringBuilder.append(Unknown Source) ~[na:1.8.0_25]
      at org.springframework.validation.AbstractErrors.toString(AbstractErrors.java:243) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
      at org.springframework.validation.BindException.getMessage(BindException.java:284) ~[spring-context-4.0.8.RELEASE.jar:4.0.8.RELEASE]
      at java.lang.Throwable.getLocalizedMessage(Unknown Source) ~[na:1.8.0_25]
      at java.lang.Throwable.toString(Unknown Source) ~[na:1.8.0_25]
      at java.lang.String.valueOf(Unknown Source) ~[na:1.8.0_25]
      at java.lang.StringBuilder.append(Unknown Source) ~[na:1.8.0_25]
  </code></pre>
  
  <p>All fields are transmitted correctly unless the email field of the child-object.</p>
  
  <p>I have no idea why the error occurs, the structure is the same, the data is valid and the funny thing is when I grab the child email element in a separate object goes it</p>
  
  <p>Does anyone have an idea?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT:</strong>
  Email class:</p>
  
  <pre><code>@Entity(name="Email")
  public class Email implements Serializable
  {
      private static final long serialVersionUID = 6891079722082340011L;
  
      @Id()
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Expose
      protected Long eMailId;
      @Expose
      protected String value;
  
      //getter/setter
  
      @Override
      public boolean equals(Object obj)
      {
          if(obj instanceof EMail){
              return value.equals(((Email) obj).getValue());
          }
          return false;
      }
  
      @Override
      public int hashCode()
      {
          return value.hashCode();
      }
  }
  </code></pre>
  
  <p>The post method:</p>
  
  <pre><code>@RequestMapping(value = "/{login}/edit", method = RequestMethod.POST)
  public ModelAndView updateUser(@PathVariable("login") final String login, @ModelAttribute final User webUser) {
      final Person repoUser = personRepository.findPersonByLogin(login);
      repoUser.updateWith(webUser);
  
      return new ModelAndView("redirect:" + URL_USERS_OVERVIEW);
  }
  </code></pre>