[rules-users] Exception during insert

Swindells, Thomas TSwindells at nds.com
Fri Mar 19 06:57:22 EDT 2010


Odd,

Looks like it is a problem in the internal of mvel, there's two things I'd suggest you could try:
Firstly try change it to be something similar to:

for (int i=0; i<ucells.length; i++)

{

UnltranCell toInsert = ucells[i];
                insert( toInsert );
      }
If you are lucky this may sort out the type inference.

The other option is to try rewriting the rule to be more declarative and not have the iteration.  This can be achieved by inserting the UtranCell array as a global (cells) and then having a rule where the when part similar to "$cell : UltranCell() from cells" and a then part which inserts the single cell returned into the knowledge base.

Thomas

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Ryan Fitzgerald
Sent: 19 March 2010 10:40
To: rules-users at lists.jboss.org
Subject: Re: [rules-users] Exception during insert

**Apologies if this post starts a new thread**


Hi Thomas,

I get a series of com.sample.UtranCell strings printed expected.

So the array seems to be correctly comprised of UtranCell objects.

I have the following import statement in the drl file:

import com.sample.UtranCell;

Weird!

/Ryan.


From: rules-users-boun... at lists.jboss.org
[mailto:rules-users-boun... at lists.jboss.org] On Behalf Of Ryan Fitzgerald
Sent: 19 March 2010 09:41
To: rules-users at lists.jboss.org
Subject: [rules-users] Exception during insert

Hi,

I get the following exception when trying to insert an object from within a
rule consequence:

[Error: object is not an instance of declaring class]

The rule is as follows:

rule "Utran Cell Selection Rule"
salience 50
dialect "java"
        when
        then
                UtranCell[] ucells =
TopologyService.getInstance().getUtranCells();
                for (int i=0; i<ucells.length; i++) {
                insert( ucells[i] );
                }
end


And it works fine if I replace the insert with System.out.println(ucells[i]) -
it seems to be something problematic with the insert. Full trace is below.

I can't see what the problem is...any ideas?

Thanks,
Ryan.

org.drools.runtime.rule.ConsequenceException: [Error: object is not an instance
of declaring class]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]
        at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
        at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
        at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
        at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
        at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
        at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
        at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
        at com.sample.DroolsTest.main(DroolsTest.java:28)
Caused by: [Error: object is not an instance of declaring class]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]
        at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:389)
        at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:138)
        at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:133)
        at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
        at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:104)
        at org.mvel2.MVEL.executeExpression(MVEL.java:995)
        at
org.drools.base.dataproviders.MVELDataProvider.getResults(MVELDataProvider.java:91)
        at org.drools.reteoo.FromNode.evaluateAndPropagate(FromNode.java:124)
        at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:104)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:117)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:28)
        at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:116)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:117)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:28)
        at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:116)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:117)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:28)
        at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:116)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:117)
        at
org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:78)
        at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:142)
        at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)
        at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:185)
        at
org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:146)
        at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1046)
        at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1001)
        at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:114)
        at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:108)
        at
com.sample.Rule_Utran_Cell_Selection_Rule_0.consequence(Rule_Utran_Cell_Selection_Rule_0.java:9)
        at
com.sample.Rule_Utran_Cell_Selection_Rule_0ConsequenceInvoker.evaluate(Rule_Utran_Cell_Selection_Rule_0ConsequenceInvoker.java:18)
        at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
        ... 6 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of
declaring class
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:931)
        at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:316)
        ... 36 more



________________________________

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

________________________________
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100319/5506d080/attachment.html 


More information about the rules-users mailing list