immutables: adding javax.validation.constraints.NotEmpty annotaion producing errors in generated code

Hi, there seems to have been some regression. I’m using immutables 2.5.5

@Value.Immutable
@BaseStyle
public abstract class UserImmutable {

    @NotEmpty
    abstract String getUsername();

}

is resulting in

/**
 * Immutable implementation of {@link UserImmutable}.
 * <p>
 * Use the builder to create immutable instances:
 * {@code User.builder()}.
 */
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "UserImmutable"})
public final class User extends UserImmutable {
  private final java.lang.@NotEmpty String username;
.
.
.
/**
   * @return The value of the {@code username} attribute
   */
  @Override
  java.lang.@NotEmpty String getUsername() {
    return username;
  }
.
.
.
}

java.lang. is being added into the generated field and method text. The import for the annotation is correctly generated. My BaseStyle is only to change the naming convention. I’m compiling using Maven, as directed in the docs.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

OK, I’ve got to the bottom of it I think. I was using 2.0 validation api, which is not supported by Oval or bval. Why they were picking the 2.0 annotations up after removing the fully qualified java.lang. I have no idea! (And it’s not that interesting now) So, working with 1.1 of the spec, if I set them on bean style getters in the Immutable, and use passAnnotations in @Value.Style then they come through and bval picks them up. I imagine things will be a bit cleaner once 2.0 spec is supported by bval but for the time being I can live with the passAnnotations hack. My apologies, I should not have been using the 2.0 jar and wasting your time. But thanks very much for the attention and I will use Immutables in my project!