NPE in BindBeanFactory when no getter #61

Closed
lorrin opened this Issue Apr 5, 2013 · 2 comments

Projects

None yet

2 participants

@lorrin
lorrin commented Apr 5, 2013

When using @BindBean and a POJO that has setters with no corresponding getters, I get NullPointerExceptions. Trace below. I think what's going on is that BindBeanFactory loops through the property descriptors and doesn't check for null in the result of prop.getReadMethod(). But per PropertyDescriptor JavaDoc, getReadMethod "may return null if the property can't be read." It looks like it simply skipping over any null results would achieve the desired result.

java.lang.IllegalStateException: unable to bind bean properties
    at org.skife.jdbi.v2.sqlobject.BindBeanFactory$1.bind(BindBeanFactory.java:34)
    at org.skife.jdbi.v2.sqlobject.BindBeanFactory$1.bind(BindBeanFactory.java:15)
    at org.skife.jdbi.v2.sqlobject.Bindifier.bind(Bindifier.java:38)
    at org.skife.jdbi.v2.sqlobject.CustomizingStatementHandler.applyBinders(CustomizingStatementHandler.java:108)
    at org.skife.jdbi.v2.sqlobject.UpdateHandler.invoke(UpdateHandler.java:56)
    at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:147)
    at org.skife.jdbi.v2.sqlobject.SqlObject$1.intercept(SqlObject.java:60)
    at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass$$EnhancerByCGLIB$$a7db5f40.record(<generated>)
...
Caused by: java.lang.NullPointerException
    at org.skife.jdbi.v2.sqlobject.BindBeanFactory$1.bind(BindBeanFactory.java:30)
    ... 40 more
@stevenschlansker stevenschlansker added a commit to stevenschlansker/jdbi that referenced this issue Apr 5, 2013
@stevenschlansker stevenschlansker Test case for #61: cause NPE in BindBeanFactory if there are writable…
… but not readable properties
8f0bd27
@stevenschlansker
Member

Hope this fixes your issue!

@lorrin
lorrin commented Apr 5, 2013

Excellent, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment