Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Null Pointer Exception in PredicateGroup

Avatar

Level 5

Hi,

I am trying to evaluate a query in AEM. This query return the result while executing in querybuilder tool : Link

During execution in code, I am getting NPE. Here is the map printed in logs :

Map is {path=/content/dam, p.limit=-1, group.3_group.property.operation=exists, group.2_daterange.upperBound=2018-07-03, group.1_daterange.property=@jcr:content/jcr:lastModified, group.1_daterange.upperBound=2018-07-03, group.2_daterange.property=@jcr:content/cq:lastReplicated, group.3_group.property=@jcr:content/expireDate, type=dam:Asset, group.3_group.property.value=false, group.p.and=true}

Below is the code snippet :

private Query prepareQueryForExpiredAssets() {

        final int monthsAgo = Integer.parseInt(assetExpirationTimeInMonths)*-1;

        final String assetExpireDate = DateTimeUtils.getCurrentDateInTextFormat(DATE_FORMAT_TYPE1, monthsAgo);

        LOGGER.info("assetExpireDate ::: {}",assetExpireDate);

        Map<String, String> map = new HashMap<String, String>();

        map.put("path", "/content/dam");

        map.put("type", "dam:Asset");

        map.put("group.p.and", "true");

        map.put("group.1_daterange.property", "@jcr:content/jcr:lastModified");

        map.put("group.1_daterange.upperBound", assetExpireDate);

    //    map.put("group.1_daterange.timeZone", "-5");

        map.put("group.2_daterange.property", "@jcr:content/cq:lastReplicated");

        map.put("group.2_daterange.upperBound", assetExpireDate);

    //    map.put("group.1_daterange.timeZone", "-5");

        map.put("group.3_group.property", "@jcr:content/expireDate");

        map.put("group.3_group.property.operation", "exists");

        map.put("group.3_group.property.value", "false");

        map.put("p.limit", "-1");

        LOGGER.info("Map is {}",map.toString());

        LOGGER.info("queryBuilder ::: {}",queryBuilder.getClass());

        return queryBuilder.createQuery(PredicateGroup.create(map), this.session);

    }

Stacktrace :

java.lang.NullPointerException: null

    at com.day.cq.search.eval.DateRangePredicateEvaluator.parseDateString(DateRangePredicateEvaluator.java:95)

    at com.day.cq.search.eval.DateRangePredicateEvaluator.getXPathExpression(DateRangePredicateEvaluator.java:68)

    at com.day.cq.search.eval.PredicateGroupEvaluator.getXPathExpression(PredicateGroupEvaluator.java:72)

    at com.day.cq.search.impl.builder.RootEvaluator.getPropertyConstraintsXpathSubExpre(RootEvaluator.java:437)

    at com.day.cq.search.impl.builder.RootEvaluator.getAllSubQueryObjects(RootEvaluator.java:399)

    at com.day.cq.search.impl.builder.RootEvaluator.getAllSubQueryObjects(RootEvaluator.java:337)

    at com.day.cq.search.impl.builder.RootEvaluator.getXPathExpressionWithUnion(RootEvaluator.java:261)

    at com.day.cq.search.impl.builder.RootEvaluator.getXPathExpression(RootEvaluator.java:95)

    at com.day.cq.search.impl.builder.QueryImpl.executeXpath(QueryImpl.java:385)

    at com.day.cq.search.impl.builder.QueryImpl.execute(QueryImpl.java:442)

    at com.day.cq.search.impl.builder.QueryImpl.getResult(QueryImpl.java:106)

Any idea to fix this issue.

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Level 5

This is solved, session object was null which caused this exception.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 5

This is solved, session object was null which caused this exception.