Consider the below code. When I analyze the code for sonar rule, it complains about "javax.validation.constraints.NotNull" but is not initialized in this constructor.
I can resolve it by initializing the field with default value ( see example here ) but it will make @NotNull annotation redundant. So my question is how to resolve this problem in best possible way.
public class Dummy {
@NotNull(message = "Dummy field cannot be null")
private Integer dummyField;
public Dummy(Integer dummyField) {
this.dummyField = dummyField;
}
public Integer getDummyField() {
return dummyField;
}
public void setDummyField(Integer dummyField) {
this.dummyField = dummyField;
}
}