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

Mario Fusco mario.fusco at gmail.com
Thu Sep 27 03:20:03 EDT 2012


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

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.

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. Nevertheless, even if Drools wouldn't suffer
of the bug you reported, my advice is to review your decision and try to
avoid to give a semantic meaning to a number set to null.

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.


More information about the rules-users mailing list