Issue Report: Runtime ClassCastException with accumulate max() on BigDecimal - Should Fail at Compile Time

17 views
Skip to first unread message

Geeta Dhamak

unread,
Dec 1, 2025, 2:04:47 AMDec 1
to Drools Usage
## Issue Report: Runtime ClassCastException with `accumulate max()` on BigDecimal - Should Fail at Compile Time

**Drools Version:** 10.0.0  
**JDK Version:** Java 21

### Problem Description

When using `accumulate` with `max()` function on a `BigDecimal` field, if the result binding type is incorrectly declared as `Double()`, the rule **compiles successfully** but **fails at runtime** with a `ClassCastException`.

### Expected Behavior
The rule compilation should fail with a type mismatch error, preventing runtime exceptions.

### Actual Behavior
- ✅ Rule compiles without errors
- ❌ Runtime failure: `java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Double`

### Reproducible Example : attached in discussion
Java class: TestRule.java
Sample drl : mySample.txt
Sample dom : Item.java
error logs : errorLog.txt

**Runtime Error:**
```
java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Double
```

### Root Cause
The `max()` accumulate function returns the same type as the input field (`BigDecimal`), but the binding declares `Double()`. The compiler does not catch this type mismatch.

### Workaround
Change the binding type to match the actual return type:
```drl
$maxSeq: BigDecimal()  // Correct
// OR
$maxSeq: Number()      // Also works (parent type)
```

### Question
Should the Drools compiler detect this type mismatch and fail at compile time rather than allowing a runtime exception? This would improve type safety and developer experience.

TestRule.java
errorLog.txt
Item.java
mySample.txt

Geeta Dhamak

unread,
Dec 17, 2025, 3:54:30 AM (7 days ago) Dec 17
to Drools Usage
Could you please share some update on my above query.

Toshiya Kobayashi

unread,
Dec 18, 2025, 12:38:43 AM (6 days ago) Dec 18
to Drools Usage
Hi,

I have reproduced the issue with 10.0.0, and confirmed that it's fixed in 10.1.0.

It's because of https://github.com/apache/incubator-kie-drools/commit/c4711a9bda44e926104c3801ad87492753ed9ecd . It was not intended to fix your exact issue, but fixed it as an extra benefit. Please try.

Toshiya

2025年12月17日水曜日 17:54:30 UTC+9 geeta...@gmail.com:
Reply all
Reply to author
Forward
0 new messages