[rules-users] how is Integer converted when comparing with primitive?

Wolfgang Laun wolfgang.laun at gmail.com
Thu Sep 27 07:00:15 EDT 2012


On 27/09/2012, Mario Fusco <mario.fusco at gmail.com> wrote:
> Hi,
>
> this is definitively a bug and I will start working asap to fix it. By the
> way which version of Drools are you using?

I'll report this in detail ASAP, using a simple example.

>
> I think that in your case null has exactly the same semantic of NaN. It
> means that any comparison against it ( even currentLateCount <=
> Integer.MAX_VALUE ) shouldn't match.

Yeah.

>
> As a side note let me underline that in my opinion something like the
> following:
>
>
> mpgong wrote
>> currentLateCount is an Integer type because i want to be able to store
>> null.  0 means something different in my app.

Note, however, that (e.g.) unmarshalling XML where an element has a
child with type xs:int and minOccurs="0", you'll have null as the
field value. So, the "different meaning" is that the value is
absent/not provided/...

>
> is profoundly wrong and there's no reason that could drive me to model
> something in that way. That is true also and especially in plain Java: try
> to use a condition like
>
> if ( currentLateCount < 100 ) { ... }
>
> in your Java code when currentLateCount is null and you will see that the
> only result you will get is a shining NullPointerException.
>
> Of course, since the LHS part of Drools rules is a declarative language, I
> wouldn't do the same there (even if I am tempted to), but as I said only
> end
> up with a non matching pattern.

Yes, as long as it defined and documented that way.

-W



>
> Thanks for having reported that.
> Mario
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/how-is-Integer-converted-when-comparing-with-primitive-tp4019975p4019989.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list