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()) {