New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE occures in query.clone #592

Closed
johnjaylward opened this Issue Dec 10, 2013 · 8 comments

Comments

Projects
None yet
2 participants
@johnjaylward

Stack Trace:
java.lang.NullPointerException
at com.google.common.collect.Sets.newHashSet(Sets.java:230)
at com.mysema.query.util.CollectionUtils.copyOf(CollectionUtils.java:82)
at com.mysema.query.DefaultQueryMetadata.clone(DefaultQueryMetadata.java:223)
at com.mysema.query.jpa.hibernate.HibernateQuery.clone(HibernateQuery.java:105)

this can be reproduced doing something like this:

QSomeTable qst = QSomeTable.someTable;
BooleanBuilder emptyBooleanBuilder = new BooleanBuilder();
HibernateQuery hq = new HibernateQuery(hibernateSession).from(qst).where(qst.someBooleanColumn.isFalse().and(emptyBooleanBuilder));

HibernateQuery hq2 = hq.clone(hibernateSession);

I believe the main problem stems from the "and" concatenating what is essentially an empty boolean builder. The null check in BooleanExpression passes because the builder actually exists, but is empty.

timowest added a commit that referenced this issue Dec 11, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Dec 11, 2013

Member

Thanks for the bug report, this has been fixed now.

Member

timowest commented Dec 11, 2013

Thanks for the bug report, this has been fixed now.

@johnjaylward

This comment has been minimized.

Show comment
Hide comment
@johnjaylward

johnjaylward Dec 12, 2013

does the fix also support recursively empty boolean builders? I'm not sure how the expr.accept(ExtractorVisitor.DEFAULT, null) call works.

does the fix also support recursively empty boolean builders? I'm not sure how the expr.accept(ExtractorVisitor.DEFAULT, null) call works.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Dec 12, 2013

Member

Yes, the delegation should work correctly.

Member

timowest commented Dec 12, 2013

Yes, the delegation should work correctly.

@johnjaylward

This comment has been minimized.

Show comment
Hide comment
@johnjaylward

johnjaylward Dec 12, 2013

one last question on this, It looks like the fix will now also allow null to be passed to the boolean builder constructor, is that correct?

new BooleanBuilder(null);

I have a few predicate building functions that return null, and I currently have to do this as a work around:
BooleanBuilder where = new BooleanBuilder().and(someFunctionThatMayReturnNull(someParam, someParam2)):

one last question on this, It looks like the fix will now also allow null to be passed to the boolean builder constructor, is that correct?

new BooleanBuilder(null);

I have a few predicate building functions that return null, and I currently have to do this as a work around:
BooleanBuilder where = new BooleanBuilder().and(someFunctionThatMayReturnNull(someParam, someParam2)):

timowest added a commit that referenced this issue Dec 12, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Dec 12, 2013

Member

Yes, that's correct, I added also a test.

Member

timowest commented Dec 12, 2013

Yes, that's correct, I added also a test.

@johnjaylward

This comment has been minimized.

Show comment
Hide comment
@johnjaylward

johnjaylward Dec 12, 2013

Awesome! Thanks!

Awesome! Thanks!

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Dec 12, 2013

Member

Released in 3.3.0.BETA2

Member

timowest commented Dec 12, 2013

Released in 3.3.0.BETA2

@timowest timowest closed this Dec 12, 2013

@johnjaylward

This comment has been minimized.

Show comment
Hide comment
@johnjaylward

johnjaylward Dec 12, 2013

Updated to the beta and removed my workarounds, looks great! Thanks for the quick release.

Updated to the beta and removed my workarounds, looks great! Thanks for the quick release.

@timowest timowest added this to the 3.3.0 milestone Apr 13, 2014

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