From a3f9c4c88902ef0a630a53b7dcf5b6c37df076b1 Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Thu, 10 Oct 2019 08:55:01 +1300 Subject: [PATCH] #1836 - NPE with findCount() on bean with @Aggregation, Regression in 11.45.1 --- .../server/deploy/BeanDescriptor.java | 8 +++++--- .../aggregation/TestAggregationCount.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java index ab0882715..1d40f53fa 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java @@ -3213,9 +3213,11 @@ public class BeanDescriptor implements BeanType, STreeType { private boolean includesAggregation(OrmQueryProperties rootProps) { if (rootProps != null) { final Set included = rootProps.getIncluded(); - for (BeanProperty property : propertiesAggregate) { - if (included.contains(property.getName())) { - return true; + if (included != null) { + for (BeanProperty property : propertiesAggregate) { + if (included.contains(property.getName())) { + return true; + } } } } diff --git a/src/test/java/org/tests/query/aggregation/TestAggregationCount.java b/src/test/java/org/tests/query/aggregation/TestAggregationCount.java index 3e88ac43a..9f32e4efe 100644 --- a/src/test/java/org/tests/query/aggregation/TestAggregationCount.java +++ b/src/test/java/org/tests/query/aggregation/TestAggregationCount.java @@ -58,6 +58,24 @@ public class TestAggregationCount extends BaseTestCase { } } + @Test + public void example_count() { + + ResetBasicData.reset(); + + LoggedSqlCollector.start(); + + int count = + Ebean.find(TEventOne.class) + .where().isNotNull("name") + .findCount(); + + assertThat(count).isGreaterThan(1); + + List sql = LoggedSqlCollector.stop(); + assertThat(trimSql(sql.get(0))).contains("select count(*) from tevent_one t0 where t0.name is not null"); + } + @Test public void testNonAggregationLazyLoading() {