title: bean validation not working with kotlin (JSR 380)
body: <p>so first of all i could not think of a better title for this question so i'm open for changes.</p>
  
  <p>I am trying to validate a bean using the bean validation mechanism (JSR-380) with spring boot.</p>
  
  <p>So i got a controller like this:</p>
  
  <pre><code>@Controller
  @RequestMapping("/users")
  class UserController {
      @PostMapping
      fun createUser(@Valid user: User, bindingResult: BindingResult): ModelAndView {
          return ModelAndView("someview", "user", user)
      }
  }
  </code></pre>
  
  <p>with this being the User class written in kotlin:</p>
  
  <pre><code>data class User(
      @field:NotEmpty
      var roles: MutableSet&lt;@NotNull Role&gt; = HashSet()
  )
  </code></pre>
  
  <p>and this being the test:</p>
  
  <pre><code>@Test
  internal fun shouldNotCreateNewTestWithInvalidParams() {
      mockMvc.perform(post("/users")
          .param("roles", "invalid role"))
          .andExpect(model().attributeHasFieldErrors("user",  "roles[]"))
  }
  </code></pre>
  
  <p><strong>Invalid Roles are mapped to null.</strong></p>
  
  <p>As you can see i want <code>roles</code> to contain at least one item with none of the items being null. 
  However when testing the above code no binding errors are reported if <code>roles</code> contains null values. It does report an error if the set is empty though.
  I was thinking that this might be an issue with how kotlin code compiles as the same code works just fine when the User class is written in java. Like this:</p>
  
  <pre><code>@Data // just lombok...
  public class User {
      @NotEmpty
      private Set&lt;@NotNull Role&gt; roles = new HashSet&lt;&gt;();
  }
  </code></pre>
  
  <p>Same Controller, same test.</p>
  
  <p>After checking the bytecode i noticed that the kotlin version is not including the nested <code>@NotNull</code> annotation (see below). </p>
  
  <p>Java:</p>
  
  <pre><code>private Ljava/util/Set; roles
  @Ljavax/validation/constraints/NotEmpty;()
  @Ljavax/validation/constraints/NotNull;() : FIELD, 0;
  @Ljavax/validation/constraints/NotEmpty;() : FIELD, null
  </code></pre>
  
  <p>Kotlin:</p>
  
  <pre><code>private Ljava/util/Set; roles
  @Ljavax/validation/constraints/NotEmpty;()
  @Lorg/jetbrains/annotations/NotNull;() // added because roles is not nullable in kotlin. this does not affect validation
  </code></pre>
  
  <p>Now the question is why?</p>
  
  <p><strong>Here's a <a href="https://github.com/DarkAtra/jsr380-kotlin-issue" rel="noreferrer">sample project</a> in case you want to try some stuff.</strong></p>