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

Collection query distinct() throws java.lang.NullPointerException for nulls values #466

Closed
AndreTheHunter opened this issue Aug 1, 2013 · 1 comment
Milestone

Comments

@AndreTheHunter
Copy link

When using distinct with a collection query, if the first value is null, a NullPointerException is thrown.
e.g. for:

public class CollectionQueryDistinctNPE {
    public static class Example {
    }

    @Test
    public void test() throws Exception {
        final Example e = alias(Example.class, "example");
        final List<Example> examples = Arrays.asList(null, new Example(), null);
        from($(e), examples).distinct().list($(e));
    }
}

throws:

java.lang.NullPointerException
    at com.mysema.query.collections.DefaultQueryEngine.distinct(DefaultQueryEngine.java:97)
    at com.mysema.query.collections.DefaultQueryEngine.evaluateSingleSource(DefaultQueryEngine.java:203)
    at com.mysema.query.collections.DefaultQueryEngine.list(DefaultQueryEngine.java:89)
    at com.mysema.query.collections.AbstractCollQuery.list(AbstractCollQuery.java:203)

A suggested fix would be to add a null check at DefaultQueryEngine:97 :

if (!list.isEmpty() && list.get(0) != null && list.get(0).getClass().isArray()) {
timowest added a commit that referenced this issue Aug 1, 2013
@timowest
Copy link
Member

Released in 3.2.3

@timowest timowest added this to the 3.2.3 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
Development

No branches or pull requests

2 participants