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

Jevon Wright jevon at jevon.org
Thu Feb 25 19:16:47 EST 2010


Hi Edson,

Thanks for the reply. I see your point, and yes it should probably remain
how it is today. It would be nice though if the documentation said that it
didn't check the types :-)

However in my case, it was only throwing ClassCastExceptions if I
specifically added the "eval(x instanceof Bar)" check, although you say that
it should be doing this anyway? Perhaps it only throws the
ClassCastException when you try to access a property, i.e. "name == 'bob'".

Also thanks for your comment on that bug. Looks like I can finally migrate
to 5.0!

Cheers
Jevon

2010/2/26 Edson Tirelli <ed.tirelli at gmail.com>

>
>    Hi Jevon,
>
>    That is a discussion we had for some time (whether "from" should check
> return type or not for matching purposes). The only reason it was not
> implemented so far is that it would possibly cause "silent failures".
> Example:
>
> Person( name == "bob" ) from $people
>
>     If $people returns an Alien() and the check is in place, the rule will
> not match and the user might not notice the reason, as the way it is today,
> it will raise a ClassCastException.
>
>     Although, in my opinion, the advantages of the check surpass the
> "silent failure" problem and we should add this check, specially because
> sometimes you have a collection of objects that share a common superclass,
> but with different actual subclasses instances, and you want to operate only
> on a give subclass.
>
>     Anyway, I will talk with Mark and possibly add this to Drools 5.1.
>
>     Regarding your keyword usage issue, I added a comment to it:
>
> https://jira.jboss.org/jira/browse/JBRULES-2218
>
>     Regards,
>       Edson
>
> 2010/2/24 Jevon Wright <jevon at jevon.org>
>
>> 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
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss by Red Hat @ www.jboss.com
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100226/20d749cb/attachment.html 


More information about the rules-users mailing list