Skip to content
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
Closed

NPE occures in query.clone #592

johnjaylward opened this issue Dec 10, 2013 · 8 comments
Milestone

Comments

@johnjaylward
Copy link

@johnjaylward johnjaylward commented Dec 10, 2013

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
Copy link
Member

@timowest timowest commented Dec 11, 2013

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

@johnjaylward
Copy link
Author

@johnjaylward johnjaylward commented 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.

@timowest
Copy link
Member

@timowest timowest commented Dec 12, 2013

Yes, the delegation should work correctly.

@johnjaylward
Copy link
Author

@johnjaylward johnjaylward commented 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)):

timowest added a commit that referenced this issue Dec 12, 2013
@timowest
Copy link
Member

@timowest timowest commented Dec 12, 2013

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

@johnjaylward
Copy link
Author

@johnjaylward johnjaylward commented Dec 12, 2013

Awesome! Thanks!

@timowest
Copy link
Member

@timowest timowest commented Dec 12, 2013

Released in 3.3.0.BETA2

@timowest timowest closed this Dec 12, 2013
@johnjaylward
Copy link
Author

@johnjaylward johnjaylward commented Dec 12, 2013

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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants