<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yes, it's same. See also, the name of rule with error not appear...<br>
<br>
Edson, I describe this in Jira too?<br>
<br>
<br>
<br>
Michael B. escreveu:
<blockquote cite="mid:17113250.post@talk.nabble.com" type="cite">
<pre wrap="">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@6bade9
org.drools.RuntimeDroolsException: Exception executing predicate
org.drools.base.mvel.MVELPredicateExpression@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:
</pre>
<blockquote type="cite">
<pre wrap=""> 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 <a class="moz-txt-link-rfc2396E" href="mailto:alessandro@siq.com.br"><alessandro@siq.com.br></a>:
</pre>
<blockquote type="cite">
<pre wrap="">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
</pre>
<blockquote type="cite">
<pre wrap="">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());
}
}
</pre>
</blockquote>
<pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<pre wrap="">
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ <a class="moz-txt-link-abbreviated" href="http://www.jboss.com">www.jboss.com</a>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<pre wrap=""><!---->
-----
Drools Noob since 5/2008
</pre>
</blockquote>
</body>
</html>