[rules-users] "from" keyword does not actually check types?

Jevon Wright jevon at jevon.org
Wed Feb 24 23:27:52 EST 2010


Hi,

I am using Drools 4.0.7, and I had a DRL rule similar to the following:

rule "..."
  when
    other : Foo( )
    x : Bar( ) from other.property

  then
    ...
end

An unexpected bug occured. In some situations, other.property would _not_ be
of type Bar, yet Drools would still think that it was. As a result I was
getting some unusual exceptions being thrown: "org.mvel.CompileException:
unable to resolve property: ..."

If I changed the rule to:
    x : Bar( ) from other.property
    eval ( x instanceof Bar )

It would instead throw a ClassCastException (i.e. "Baz cannot be cast into
Bar").

If, instead, I changed the rule to:
    x : Bar( other.property == x )

It would start working correctly, and 'x' would only be of type Bar.

Is this known behaviour? Is it expected? If so, I would appreciate it if the
4.0.7 documentation was updated to reflect that "from" actually ignores the
return type of properties. It took me a couple of hours to detect and fix
this bug.

I would try these rules in Drools 5.x, but I'm still waiting for the
blocking JBRULES-2218 to be resolved.

Cheers
Jevon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100225/aa03259c/attachment.html 


More information about the rules-users mailing list