Skip to content

Commit

Permalink
[DROOLS-6284] Rules not fired when RUN_TYPE==STANDARD_FROM_DRL and wh… (
Browse files Browse the repository at this point in the history
apache#3704)

* [DROOLS-6284] Rules not fired when RUN_TYPE==STANDARD_FROM_DRL and when the constraint is jitted

* - Removed non Comparable object test as not supported
  • Loading branch information
tkobayas committed Jun 29, 2021
1 parent b542592 commit 43ad37a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,24 @@ private static boolean contains(short[] list, short primitiveItem) {
}

public static boolean coercingComparison(Object obj1, Object obj2, String op) {
try {
double d1 = toDouble( obj1 );
double d2 = toDouble( obj2 );

if (Double.isNaN( d1 ) || Double.isNaN( d2 )) {
return false;
}

switch (op) {
case "<": return d1 < d2;
case "<=": return d1 <= d2;
case ">": return d1 > d2;
case ">=": return d1 >= d2;
}

} catch (NumberFormatException nfe) { }
if (canCoerceToNumber(obj1, obj2)) {
try {
double d1 = toDouble( obj1 );
double d2 = toDouble( obj2 );

if (Double.isNaN( d1 ) || Double.isNaN( d2 )) {
return false;
}

switch (op) {
case "<": return d1 < d2;
case "<=": return d1 <= d2;
case ">": return d1 > d2;
case ">=": return d1 >= d2;
}

} catch (NumberFormatException nfe) { }
}

String s1 = obj1.toString();
String s2 = obj2.toString();
Expand All @@ -279,6 +281,15 @@ public static boolean coercingComparison(Object obj1, Object obj2, String op) {
throw new UnsupportedOperationException("Unable to compare " + obj1 + " and " + obj2);
}

private static boolean canCoerceToNumber(Object left, Object right) {
// don't coerce to number when the left type is String and the right type is not number (to meet mvel behaviour)
if (left instanceof String && !(right instanceof Number)) {
return false;
} else {
return true;
}
}

private static double toDouble(Object obj) {
return obj instanceof Number ? ((Number)obj).doubleValue() : Double.parseDouble( obj.toString() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,6 @@ public void testJoinStringToObject5() {
ksession.dispose();
}

@Test
public void testJoinStringToObjectNonComparable() {

KieSession ksession = getKieSessionForJoinStringToObject();

// Object > String "10"
ksession.insert(new StringHolder("10"));
ksession.insert(new ObjectHolder(new Object())); // not Comparable
assertEquals(0, ksession.fireAllRules()); // in case of standard-drl, MathProcessor.doOperationNonNumeric() returns false when the left operand is not Comparable
}

private KieSession getKieSessionForJoinIntegerToObject() {

final String drl1 =
Expand Down

0 comments on commit 43ad37a

Please sign in to comment.