[rules-users] Property Navigation

Michael B. michael.bain at mckesson.com
Wed May 7 15:50:39 EDT 2008


Verified this, in my example if I change the line to Bar.setFoo(null) I get
the following error in my test case:

Exception executing predicate
org.drools.base.mvel.MVELPredicateExpression at 6bade9
org.drools.RuntimeDroolsException: Exception executing predicate
org.drools.base.mvel.MVELPredicateExpression at 6bade9
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:216)
	at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:132)
	at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
	at org.drools.reteoo.Rete.assertObject(Rete.java:175)
	at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
	at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:909)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:881)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:682)
	at mmg.cm.drools.FooBarTest.testProperties(FooBarTest.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.mvel.CompileException: unable to resolve property: name
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:288)
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
	at
org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:29)
	at
org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:77)
	at
org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:26)
	at
org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21)
	at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
	at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
	at org.mvel.MVEL.executeExpression(MVEL.java:235)
	at
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:36)
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:210)
	... 28 more
Caused by: org.mvel.PropertyAccessException: unable to resolve property:
name
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:382)
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:257)
	... 38 more



Edson Tirelli-3 wrote:
> 
>    Really? That is a surprise to me... we need to handle that...
> 
>    Maybe you can open a JIRA for us?
> 
>    Thanks,
>       Edson
> 
> 2008/5/6 Alessandro Lazarotti <alessandro at siq.com.br>:
> 
>> Thanks Michael, I simulate.. your rule fire with successful.
>>
>> I discovered the problem. The object in property (like Foo in your
>> example), when null, it's not throws NullPointerException, but
>> "org.mvel.PropertyAccessException: unable to resolve property".
>> With that, I never imagined that the problem was nullPointer, but I
>> thought about any access visibility (duh!).
>>
>> []'s
>> Alessandro
>>
>>
>>
>> Michael B. escreveu:
>>
>>  Okay, I wrote a test case around the following and it works fine so let
>> > me
>> > know if this isnt what you are working with...
>> >
>> > Foo Class
>> >
>> > public class Foo {
>> >        private String m_name;
>> >        public String getName()
>> >    {
>> >        return m_name;            }
>> >        public void setName(String nm)
>> >    {
>> >        m_name = nm;
>> >    }
>> >
>> > }
>> >
>> >
>> > Bar Class
>> >
>> > public class Bar {
>> >        private Foo m_foo;
>> >        public Foo getFoo()
>> >    {
>> >        return m_foo;
>> >    }
>> >        public void setFoo(Foo f)
>> >    {
>> >        m_foo = f;
>> >    }
>> >        public String toString()
>> >    {
>> >        return "I have a foo with a name of " + m_foo.getName();
>> >    }
>> >
>> > }
>> >
>> > DRL Rule
>> >
>> > rule "FooBar Rule"
>> >
>> >        when
>> >                $bar : Bar( foo.name != "Wrong" )
>> >        then        System.out.println("Test Successful - " +
>> > $bar.toString());
>> >
>> > end
>> >
>> >
>> > Junit Test Case
>> >
>> >    public void testProperties()    {
>> >        try
>> >        {
>> >            final Reader source = new InputStreamReader(
>> > FooBarTest.class.getResourceAsStream( "FooBar.drl" ) );
>> >            RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>> >            PackageBuilder builder = new PackageBuilder();
>> >                        builder.addPackageFromDrl(source);
>> >                        if ( builder.hasErrors() ) {
>> >                System.out.println( builder.getErrors().toString() );
>> >                throw new RuntimeException( "Unable to compile
>> > \"FooBar.drl\".");
>> >            }
>> >                        //get the compiled package (which is
>> > serializable)
>> >            final Package pkg = builder.getPackage();
>> >
>> >            //add the package to a rulebase (deploy the rule package).
>> >            ruleBase.addPackage( pkg );
>> >            final StatefulSession session =
>> > ruleBase.newStatefulSession();
>> >                        Foo foo = new Foo();
>> >            foo.setName("Test");
>> >            Bar bar = new Bar();
>> >            bar.setFoo(foo);
>> >            session.insert(bar);
>> >                        session.fireAllRules();
>> >    }
>> >        catch (Exception e)
>> >        {
>> >            System.out.println(e.getMessage());
>> >            e.printStackTrace();
>> >            fail(e.getMessage());
>> >        }
>> >
>> >    }
>> >
>> >
>> >
>> >
>> >
>> >
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> 
> 
> 
> -- 
> Edson Tirelli
> JBoss Drools Core Development
> Office: +55 11 3529-6000
> Mobile: +55 11 9287-5646
> JBoss, a division of Red Hat @ www.jboss.com
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 


-----
Drools Noob since 5/2008
-- 
View this message in context: http://www.nabble.com/Property-Navigation-tp17089209p17113250.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list