[JAVA] S2637 "@NonNull" values should not be set to null and empty constructors for JPA

600 views
Skip to first unread message

CSchulz

unread,
Jun 7, 2016, 9:16:45 AM6/7/16
to SonarQube
Hello,

I have recognized that S2637 finds protected no-arg constructors and marks it as violation of S2637.

We are using always a protected no-arg constructor in @Entity annotated classes for the JPA runtime.

Is there the possibility to ignore such constructors if there is a sufficient other constructor?

@Entity
public class User {
    @Id
    @NotNull
    private int id;
    @NotNull
    @Column(name = "email", nullable = false)
    private String eMail;
    @NotNull
    @Column(name = "username", nullable = false)
    private String userName;
    protected User() {
        // For JPA ignore this constructor
    }
    public User(int id, String userName, String name, String password, String eMail) {
        this.id = id;
        this.eMail = eMail;
        this.userName = userName;
        this.name = name;
        this.password = password;
    }


Best Regards

Michael Gumowski

unread,
Jul 12, 2016, 3:47:12 AM7/12/16
to CSchulz, SonarQube
Hello Christian,

Sorry for the very long delay answering you... And thanks a lot for the feedback!
Indeed, the rule should ignore default no-arg constructors for JPA entities. I update the scopre of the following ticket to cover this case: https://jira.sonarsource.com/browse/SONARJAVA-1681

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/3c0679b7-a8e2-49ed-b5b3-82e04d524c91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages