Skip to content

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

@AndreTheHunter

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions