bean-checker library

Bean checker is a Java library which helps to check that all properties of a Java bean have been set (no matter if they were set to not-null or null values).

For instance, imagine this bean:

public class SimpleBean {
    private Date date;
    private String author;
    private String body;

    public Date getDate() {
        return date;

    public void setDate(Date date) { = date;

    public String getAuthor() {
        return author;

    public void setAuthor(String author) { = author;

    public String getBody() {
        return body;

    public void setBody(String body) {
        this.body = body;



And the calling code:

SimpleBean messageBean = new SimpleBean();

messageBean.setDate(new Date());

You see above that the developer forgot to call the setBody() setter.

You can avoid situations like these by using this library, like this:

BeanChecker<SimpleBean> beanChecker = BeanCheckerFactory.createBeanChecker(SimpleBean.class);
SimpleBean messageBean = beanChecker.getBeanProxy();

messageBean.setDate(new Date());

beanChecker.mandatorySettersCalled(); // this will throw an exception if not all setters were called


Maven dependency:  (stored on maven central, no need for special repository entries)


github page:

I know there are some other solutions, like a constructor with all the fields of the bean, grouping setters together, etc; but all these solutions have their pros and cons. This library is very easy to integrate into existing code, especially for debugging purposes. It probably can be even integrated in unit-tests, if there’s a way to construct/inject the bean from the unit-test. Give it a try 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s