title: why my spring validation annotations doesnt work
body: <p>i have simple for where i put one string and im using annotations to valid the value
  and it doesnt work</p>
  
  <p>here is my class:</p>
  
  <pre><code>public class Destination
  {
      @NotNull
      String address;
  
      public Destination(){}
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  }
  </code></pre>
  
  <p>here is my controller method</p>
  
  <pre><code>@RequestMapping(value = "/search", method = RequestMethod.POST)
  public String findDestination(@ModelAttribute("destination") @Valid Destination destination, BindingResult result, RedirectAttributes redirectAttrs) {
      if(result.hasErrors()) {
          return "redirect:/";
      }
      Location location = LocationManager.getLocation(destination.getAddress());
      Weather weather = WeatherManager.getWeather(location);
      redirectAttrs.addFlashAttribute("weather", weather);
      redirectAttrs.addFlashAttribute("location", location);
      return "redirect:/";
  }
  </code></pre>
  
  <p>and here is my form in jsp file:</p>
  
  <pre><code>    &lt;form:form method="post" action="search" commandName="destination" class="form-horizontal"&gt;
      &lt;div class="control-group"&gt;
          &lt;div class="controls"&gt;
              &lt;form:input path="address" placeholder="Enter destination address"/&gt;
              &lt;form:errors path="address" cssclass="error"&gt;&lt;/form:errors&gt;
              &lt;input type="submit" value="Search" class="btn"/&gt;
              &lt;/form:form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>so the problem is that it doesnt valid my input
  when i left it empty it still try to get addres for location object from null destination object and i get the exception
  <code>HTTP Status 500 - Request processing failed; nested exception is java.util.NoSuchElementException</code></p>
  
  <pre><code>exception
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.util.NoSuchElementException
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  root cause
  
  java.util.NoSuchElementException
      java.util.ArrayList$Itr.next(ArrayList.java:794)
      com.springapp.mvc.domain.LocationManager.getLocation(LocationManager.java:52)
      com.springapp.mvc.controller.HomeController.findDestination(HomeController.java:51)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  </code></pre>