Could you expand upon why this is a poor practice? I assumed that if a part
of the pattern doesn't match the expression evaluation is terminated
laune wrote
I can anticipate the answer where OP says that there is a constraint
restricting argVolume to > 0. However, I don't think that independent
constraints such as we see them in this rule are evaluated as if they
were in a single logical expression, with Java semantics.
The seductive possibility of binding to a half-baked expression (i.e.,
$ratio:(volumeAccumulations["total"]/consolidatdVolume.avgVolume))
should be discarded. This value can safely be computed on the RHS
where the denominator's value being !=0 is asserted.
-W
On 01/11/2013, Stephen Masters <
stephen.masters@
> wrote:
> Divide by zero exceptions usually occur when you try to divide by zero.
>
> So … first question … is consolidatdVolume.avgVolume ever zero?
>
>
> On 1 Nov 2013, at 16:17, gboro54 <
gboro54@
> wrote:
>
>> I have rules like the following:
>>
>> rule "Add Baseline to Context if it does not exists exists or not
>> greater
>> then 0"
>> no-loop true
>> when
>> $context:Context($id:id,baselineParticipation==null ||
>>
>>
baselineParticipation.baselineRatio==null||baselineParticipation.baselineRatio==0)
>> then
>> modify($firm) {setBaselineParticipation(new
>> BaselineParticipation($id,new
>> BigDecimal(0.00485)))};
>>
>> end
>>
>> rule "Calculate Participation Ratio"
>> no-loop true
>> when
>>
>> $context:Context(consolidatdVolume!=null,consolidatdVolume.avgVolume>0,
>>
>>
volumeAccumulations["total"]!=null,volumeAccumulations["total"]>0,
>>
>> $ratio:(volumeAccumulations["total"]/consolidatdVolume.avgVolume))
>> then
>> ConcurrentMap calculatedRatios=$firm.getCalculatedRatios();
>> calculatedRatios.put("fparticipationRatio",new BigDecimal($ratio));
>> modify($firm){setCalculatedRatios(calculatedRatios)};
>> end
>>
>> Despite the checks I get the following exception and any insight into
>> why
>> would be great:
>>
>> Exception executing consequence for rule "Calculate Firm Participation
>> Ratio" in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
>> zero
>> Exception executing consequence for rule "Calculate Firm Participation
>> Ratio" in com.nasdaq.rms.nq.status: java.lang.ArithmeticException: / by
>> zero
>> at
>>
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
>> at
>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
>> at
>> org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
>> at
>> org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
>> at
>>
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
>> at
>>
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
>> at
>>
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
>> at
>>
com.nasdaq.fq.rms.workflow.processor.rules.PerformanceStatusAssignmentProcessor.doWork(PerformanceStatusAssignmentProcessor.java:156)
>> at
>> com.ften.ssr.workqueue.WorkItemRunnable.run(WorkItemRunnable.java:48)
>> at
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>> at java.lang.Thread.run(Thread.java:724)
>> Caused by: java.lang.ArithmeticException: / by zero
>> at ConditionEvaluatorda6271cf5a744b6bbdb9c717cae2edb7.evaluate(Unknown
>> Source)
>> at
>> org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
>> at
>> org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
>> at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154)
>> at
>>
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
>> at
>>
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
>> at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
>> at
>>
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
>> at
>>
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
>> at
>> org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
>> at
>> org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
>> at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483)
>> at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:383)
>> at
>> org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:337)
>> at
>>
com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175.defaultConsequence(Unknown
>> Source)
>> at
>>
com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175DefaultConsequenceInvokerGenerated.evaluate(Unknown
>> Source)
>> at
>>
com.nasdaq.rms.nq.status.Rule_Calculate_Firm_Participation_Ratio_cfb033f33c2b404fb2bff8e1b9af0175DefaultConsequenceInvoker.evaluate(Unknown
>> Source)
>> at
>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
>> ... 10 more
>>
>>
>>
>> --
>> View this message in context:
>>
http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026...
>> Sent from the Drools: User forum mailing list archive at
Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>>
rules-users@.jboss
>
>
>
> _______________________________________________
> rules-users mailing list
>
rules-users@.jboss
>
_______________________________________________
rules-users mailing list
rules-users@.jboss
--
View this message in context:
http://drools.46999.n3.nabble.com/Drools-5-5-divide-by-0-exception-tp4026...
Sent from the Drools: User forum mailing list archive at
Nabble.com.