This is an automated email from the ASF dual-hosted git repository.

yamer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/main by this push:
     new afde3730d2 [incubator-kie-issues#1771] Fixing BooleanEvalHelper to 
avoid class cast exceptions (#6229)
afde3730d2 is described below

commit afde3730d2b6dae20dfc8b9090c1525fc3fdb3c6
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Thu Jan 23 16:36:15 2025 +0100

    [incubator-kie-issues#1771] Fixing BooleanEvalHelper to avoid class cast 
exceptions (#6229)
    
    Co-authored-by: Gabriele-Cardosi <[email protected]>
---
 .../org/kie/dmn/feel/util/BooleanEvalHelper.java   | 16 +++++-----
 .../kie/dmn/feel/runtime/FEELTernaryLogicTest.java |  9 ++++--
 .../kie/dmn/feel/util/BooleanEvalHelperTest.java   | 34 ++++++++++++++++++++++
 3 files changed, 48 insertions(+), 11 deletions(-)

diff --git 
a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java
 
b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java
index 9ebcb598d8..104002e898 100644
--- 
a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java
+++ 
b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -205,15 +205,13 @@ public class BooleanEvalHelper {
      * @return
      */
     public static Boolean getBooleanOrDialectDefault(Object rawReturn, 
FEELDialect feelDialect) {
-        if (feelDialect.equals(FEELDialect.BFEEL)) {
-            if (rawReturn instanceof Boolean bool) {
-                return bool;
-            } else {
-                return false;
-            }
-        } else {
-            return (Boolean) rawReturn;
+        Boolean toReturn = null;
+        if (rawReturn instanceof Boolean bool) {
+            toReturn = bool;
+        } else if (feelDialect.equals(FEELDialect.BFEEL)) {
+            toReturn = false;
         }
+        return toReturn;
     }
 
     /**
diff --git 
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELTernaryLogicTest.java
 
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELTernaryLogicTest.java
index 42f779a768..43a13c3a8c 100644
--- 
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELTernaryLogicTest.java
+++ 
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELTernaryLogicTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -58,7 +58,12 @@ public class FEELTernaryLogicTest extends BaseFEELTest {
                 { "false and false or true", Boolean.TRUE , null},
                 { "false and (false or true)", Boolean.FALSE , null},
                 { "true or false and false", Boolean.TRUE , null},
-                { "(true or false) and false", Boolean.FALSE , null}
+                { "(true or false) and false", Boolean.FALSE , null},
+                //
+                { "123 and false", Boolean.FALSE , null},
+                { "\"true\" and false", Boolean.FALSE , null},
+                { "123 or true", Boolean.TRUE , null},
+                { "\"true\" or true", Boolean.TRUE , null}
         };
         return addAdditionalParameters(cases, false);
     }
diff --git 
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/BooleanEvalHelperTest.java
 
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/BooleanEvalHelperTest.java
index b869e0ab19..2e9dd2ff92 100644
--- 
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/BooleanEvalHelperTest.java
+++ 
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/BooleanEvalHelperTest.java
@@ -28,6 +28,8 @@ import org.mockito.MockedStatic;
 import org.mockito.Mockito;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static 
org.kie.dmn.feel.util.BooleanEvalHelper.getBooleanOrDialectDefault;
+import static org.kie.dmn.feel.util.BooleanEvalHelper.getFalseOrDialectDefault;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 
@@ -50,6 +52,38 @@ class BooleanEvalHelperTest {
         assertThat(BooleanEvalHelper.compare(BigInteger.valueOf(1), 2.3,  
FEELDialect.FEEL,(l, r) -> l.compareTo(r) == 0)).isFalse();
     }
 
+    @Test
+    void getBooleanOrDialectDefaultFEEL() {
+        assertThat(getBooleanOrDialectDefault(false, 
FEELDialect.FEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getBooleanOrDialectDefault(true, 
FEELDialect.FEEL)).isEqualTo(Boolean.TRUE);
+        assertThat(getBooleanOrDialectDefault("true", 
FEELDialect.FEEL)).isNull();
+        assertThat(getBooleanOrDialectDefault(null, 
FEELDialect.FEEL)).isNull();
+    }
+
+    @Test
+    void getBooleanOrDialectDefaultBFEEL() {
+        assertThat(getBooleanOrDialectDefault(false, 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getBooleanOrDialectDefault(true, 
FEELDialect.BFEEL)).isEqualTo(Boolean.TRUE);
+        assertThat(getBooleanOrDialectDefault("true", 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getBooleanOrDialectDefault(null, 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+    }
+
+    @Test
+    void getFalseOrDialectDefaultFEEL() {
+        assertThat(getFalseOrDialectDefault(false, 
FEELDialect.FEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getFalseOrDialectDefault(true, FEELDialect.FEEL)).isNull();
+        assertThat(getFalseOrDialectDefault("true", 
FEELDialect.FEEL)).isNull();
+        assertThat(getFalseOrDialectDefault(null, FEELDialect.FEEL)).isNull();
+    }
+
+    @Test
+    void getFalseOrDialectDefaultBFEEL() {
+        assertThat(getFalseOrDialectDefault(false, 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getFalseOrDialectDefault(true, 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getFalseOrDialectDefault("true", 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+        assertThat(getFalseOrDialectDefault(null, 
FEELDialect.BFEEL)).isEqualTo(Boolean.FALSE);
+    }
+
     @Test
     void isEqualsSCWithStringValue() {
         assertThat(BooleanEvalHelper.isEqualsStringCompare("", "")).isTrue();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to