You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by ya...@apache.org on 2026/05/27 08:51:20 UTC

(incubator-kie-drools) branch main updated: [incubator-kie-drools-6711] Fix NoSuchMethodError in ASM-jitted constraints with EvaluatorWrapper (#6730)

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

yesamer 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 967c51e73d [incubator-kie-drools-6711] Fix NoSuchMethodError in ASM-jitted constraints with EvaluatorWrapper (#6730)
967c51e73d is described below

commit 967c51e73d84f68f0cd59fba713f9e3936c135a3
Author: Toshiya Kobayashi <to...@gmail.com>
AuthorDate: Wed May 27 17:51:14 2026 +0900

    [incubator-kie-drools-6711] Fix NoSuchMethodError in ASM-jitted constraints with EvaluatorWrapper (#6730)
    
    ASMConditionEvaluatorJitter.jitOperators() generated bytecode calling
    EvaluatorHelper.initOperators with Tuple.class as the second parameter
    type, but commit 81dce55001 changed the actual method signature to use
    BaseTuple.class. This mismatch caused NoSuchMethodError at runtime when
    an MVELConstraint with non-empty EvaluatorWrapper[] (e.g. str operator
    with a variable binding on a typesafe type) was ASM-jitted.
    
    Co-authored-by: Claude Opus 4.6 (1M context) <no...@anthropic.com>
---
 .../drools/mvel/ASMConditionEvaluatorJitter.java   |  2 +-
 .../mvel/ASMConditionEvaluatorJitterTest.java      | 53 ++++++++++++++++++++++
 .../drools/mvel/integrationtests/JittingTest.java  | 32 +++++++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/drools-mvel/src/main/java/org/drools/mvel/ASMConditionEvaluatorJitter.java b/drools-mvel/src/main/java/org/drools/mvel/ASMConditionEvaluatorJitter.java
index 3377bc5029..1b2756b041 100644
--- a/drools-mvel/src/main/java/org/drools/mvel/ASMConditionEvaluatorJitter.java
+++ b/drools-mvel/src/main/java/org/drools/mvel/ASMConditionEvaluatorJitter.java
@@ -240,7 +240,7 @@ public class ASMConditionEvaluatorJitter {
             mv.visitVarInsn(ALOAD, 1); // InternalFactHandle
             mv.visitVarInsn(ALOAD, 3); // Tuple
             getFieldFromThis("operators", EvaluatorWrapper[].class);
-            invokeStatic(EvaluatorHelper.class, "initOperators", void.class, FactHandle.class, Tuple.class, EvaluatorWrapper[].class);
+            invokeStatic(EvaluatorHelper.class, "initOperators", void.class, FactHandle.class, BaseTuple.class, EvaluatorWrapper[].class);
         }
 
         private void jitCondition(Condition condition) {
diff --git a/drools-mvel/src/test/java/org/drools/mvel/ASMConditionEvaluatorJitterTest.java b/drools-mvel/src/test/java/org/drools/mvel/ASMConditionEvaluatorJitterTest.java
new file mode 100644
index 0000000000..dc8be65a6a
--- /dev/null
+++ b/drools-mvel/src/test/java/org/drools/mvel/ASMConditionEvaluatorJitterTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.mvel;
+
+import org.drools.base.rule.Declaration;
+import org.drools.base.rule.accessor.Evaluator;
+import org.drools.compiler.rule.builder.EvaluatorWrapper;
+import org.drools.core.common.DefaultFactHandle;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThatNoException;
+import static org.mockito.Mockito.mock;
+
+class ASMConditionEvaluatorJitterTest {
+
+    @Test
+    void jitWithNonEmptyOperators() throws Exception {
+        // incubator-kie-drools#6711
+        // ASMConditionEvaluatorJitter.jitOperators() must generate bytecode calling
+        // EvaluatorHelper.initOperators with BaseTuple.class (not Tuple.class) as
+        // the second parameter, matching the actual method signature.
+        java.lang.reflect.Constructor<ConditionAnalyzer.FixedValueCondition> ctor =
+                ConditionAnalyzer.FixedValueCondition.class.getDeclaredConstructor(boolean.class);
+        ctor.setAccessible(true);
+        ConditionAnalyzer.Condition condition = ctor.newInstance(true);
+
+        Declaration[] declarations = new Declaration[0];
+        Evaluator mockEvaluator = mock(Evaluator.class);
+        EvaluatorWrapper[] operators = new EvaluatorWrapper[]{ new EvaluatorWrapper(mockEvaluator, null, null) };
+
+        ConditionEvaluator evaluator = ASMConditionEvaluatorJitter.jitEvaluator(
+                "true", condition, declarations, operators, getClass().getClassLoader(), null);
+
+        assertThatNoException().isThrownBy(() ->
+                evaluator.evaluate(new DefaultFactHandle(1, new Object()), null, null));
+    }
+}
diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/JittingTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/JittingTest.java
index 19f75167c9..b66951c6c9 100644
--- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/JittingTest.java
+++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/JittingTest.java
@@ -491,4 +491,36 @@ public class JittingTest {
         ksession.insert(person);
         assertThat(ksession.fireAllRules()).isEqualTo(1);
     }
+
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    void jitStrOperatorWithVariable(KieBaseTestConfiguration kieBaseTestConfiguration) {
+        // incubator-kie-drools#6711
+        // The 'str' operator with a variable binding creates an MVELConstraint with
+        // non-empty EvaluatorWrapper[] on a typesafe POJO (isDynamic=false).
+        // With jit threshold 0, the ASM jitter generates bytecode calling
+        // EvaluatorHelper.initOperators with Tuple.class instead of BaseTuple.class.
+
+        String drl =
+                "declare Item\n" +
+                "    name : String\n" +
+                "end\n" +
+                "rule Init when then insert(new Item(\"hello\")); end\n" +
+                "rule R when\n" +
+                "    $prefix : String()\n" +
+                "    Item( name str[startsWith] $prefix )\n" +
+                "then\n" +
+                "end\n";
+
+        final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, drl);
+        final KieBase kieBase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(
+                kieModule, kieBaseTestConfiguration, ConstraintJittingThresholdOption.get(0));
+        final KieSession ksession = kieBase.newKieSession();
+        try {
+            ksession.insert("hel");
+            assertThat(ksession.fireAllRules()).isEqualTo(2);
+        } finally {
+            ksession.dispose();
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org