[jboss-jira] [JBoss JIRA] (JBRULES-3466) sum with no matching values results in NPE on reverse

Chris Dolan (JIRA) jira-events at lists.jboss.org
Mon Apr 16 19:00:17 EDT 2012


Chris Dolan created JBRULES-3466:
------------------------------------

             Summary: sum with no matching values results in NPE on reverse
                 Key: JBRULES-3466
                 URL: https://issues.jboss.org/browse/JBRULES-3466
             Project: Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: drools-planner
    Affects Versions: 5.4.0.CR1
         Environment: drools-planner 5.4.0-SNAPSHOT, snapshot downloaded on Apr 9, 2012
            Reporter: Chris Dolan
            Assignee: Geoffrey De Smet


I have a rule with this element in the when clause:

{noformat}
        $beforePrediction : Number() from accumulate(
             JobSlot(job != NULL_JOB, $j : job, $service == service, $ordinal > ordinal) and $p : Prediction(job == $j, service == $service),
             sum($p.getMillisMid())
        )
{noformat}

When I execute this I have cases where there are no matching Prediction instances, so the sum is zero. Later on retract, I get this:

{noformat}
Caused by: java.lang.NullPointerException: null
	at org.drools.base.accumulators.SumAccumulateFunction.reverse(SumAccumulateFunction.java:83)
	at org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.reverse(JavaAccumulatorFunctionExecutor.java:130)
	at org.drools.rule.Accumulate.reverse(Accumulate.java:208)
{noformat}

The relevant code is this:

{noformat}
    public void accumulate(Serializable context,
                           Object value) {
        SumData data = (SumData) context;
        data.total += ((Number) value).doubleValue();
    }
{noformat}

and this:

{noformat}
    public void reverse(Object workingMemoryContext,
                        Object context,
                        Tuple leftTuple,
                        InternalFactHandle handle,
                        Declaration[] declarations,
                        Declaration[] innerDeclarations,
                        WorkingMemory workingMemory) throws Exception {

        final Object value = ((JavaAccumulatorFunctionContext) context).reverseSupport.remove( Integer.valueOf( handle.getId() ) );
        this.function.reverse( ((JavaAccumulatorFunctionContext) context).context,
                               value );
    }
{noformat}

A breakpoint reveals that handle is a Prediction instance. Somehow that handle was not added to reverseSupport, apparently.



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list