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

Swindells, Thomas TSwindells at nds.com
Wed Mar 3 06:52:55 EST 2010


I'm not convinced about the silent failure argument as I don't see how it is any different from the silent failure you get if the type doesn't exist in the 'main' knowledge base - this is probably because the way I conceptualize the from keyword is to say "don't use the normal knowledge base but instead treat this collection as a knowledge base and run this predicate over that instead".

I find the lack of a type check far more surprising than I would a silent failure - afterall you'll still get a silent failure if the predicate you put inside the type is incorrect and in lots of other places within drools so I'm not sure what is special about this particular type of silent 'failure'.

Anyway this is my view,

Thomas


> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org [mailto:rules-users-
> bounces at lists.jboss.org] On Behalf Of Simon Thum
> Sent: 03 March 2010 11:08
> To: Rules Users List
> Subject: Re: [rules-users] "from" keyword does not actually check types?
>
> Edson Tirelli wrote:
> >    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.
> FWIW, I'd appreciate both options being possible. Maybe an explicit
> qualification makes sense, like
>
>  (subset|all)? from ...
>
> so you'd retain error checks where appropriate.
>
>
> >
> >     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
> >>
> >>
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


**************************************************************************************
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




More information about the rules-users mailing list