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

Closed
AndreTheHunter opened this Issue Aug 1, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@AndreTheHunter

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 27, 2013

Member

Released in 3.2.3

Member

timowest commented Aug 27, 2013

Released in 3.2.3

@timowest timowest closed this Aug 27, 2013

@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