You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "orit1992 (via GitHub)" <gi...@apache.org> on 2025/02/03 16:08:55 UTC
[I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
orit1992 opened a new issue, #6243:
URL: https://github.com/apache/incubator-kie-drools/issues/6243
I've encountered an issue in Drools **8.44.0.Final** where rule execution changes **depending on whether a subclass overrides a getter from its superclass**. Even more concerning, in some cases, **a property that is actually non-null gets evaluated as null in WHEN condition**.
I was able to verify that the issue occurs for sure in Drools versions from **7.74.1** up to **10.0.0** (latest available version) using both Java11 and Java17, the version **6.5.0.Final** doesn't have the issue.
**Steps to Reproduce**
Consider the following examples rules:
``` drl
rule "Set Address"
salience 1
when
$fact : Person( address == null)
then
System.out.println("Person Hash " + $fact.hashCode());
modify($fact) {
setAddress("ROME")
}
end
rule "Set worker name"
when
$fact : Worker(
$address: address != null
)
then
System.out.println("Worker Hash " + $fact.hashCode());
System.out.println("(address != null) evaluated and address is " + $address );
modify($fact) {
setName("PIPPO")
}
end
```
And the following Java classes:
``` java
public class Person {
private String name;
private int age;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
public class Worker extends Person {
// If this override is removed, the rule "Set worker name" works fine.
@Override
public String getAddress() {
return super.getAddress();
}
}
public class Student extends Person {}
```
**Unexpected Behavior**
- If `Worker` **does NOT override** `getAddress()`, the rule `"Set worker name"` **executes**, and `name` is set to "PIPPO".
- If `Worker` **overrides** `getAddress()`, the rule `"Set worker name"` **is never triggered**.
- The only difference between the two scenarios is the overridden method in Worker, which should not affect rule execution logic.
**Even More Concerning**: **Evaluation of** `null` **When the Value is Non-Null**
To illustrate a more severe case, consider the following additional rule:
``` drl
/**
* When Worker class overrides getAddress(), then `address == null` evaluates to true,
* but it will print a non-null value.
* Uncomment the following rule and comment the previous ones to test.
*/
rule "Check worker address"
when
$fact : Worker( $address: address == null )
then
System.out.println("Worker Hash " + $fact.hashCode());
System.out.println("(address == null) evaluated but address is " + $address);
modify($fact) {
setName("PIPPO");
}
end
```
With this setup:
- Drools evaluates `address == null` as `true`, even when `getAddress()` actually returns a **non-null** value.
- The rule fires, but the printed value of $address is unexpectedly **not null**.
---
To help reproduce this issue, I've created a [repo](https://github.com/orit1992/droolsbehavior/tree/main) containing Maven project (Java17) with unit tests that demonstrate the behavior:
**Student** class: extends Person and **Does not override** `getAddress()`, and the rule execution works as expected (`com.example.DroolsRuleTest#testStudentSessionAddress`).
**Worker** class: extends Person and **Overrides** `getAddress()`, causing the rule execution to **fail** (`com.example.DroolsRuleTest#testWorkerSessionAddress`).
Thanks for your time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas commented on issue #6243:
URL: https://github.com/apache/incubator-kie-drools/issues/6243#issuecomment-2647015113
Thank you for providing the reproducer! I'm looking and keep you posted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas commented on issue #6243:
URL: https://github.com/apache/incubator-kie-drools/issues/6243#issuecomment-2670881033
The issue has been fixed in main branch. It means the next minor release `10.1.0` will include the fix. We expect it will be released in 2 or 3 months. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas commented on issue #6243:
URL: https://github.com/apache/incubator-kie-drools/issues/6243#issuecomment-2647728161
Hi @orit1992 , I reproduced the issue and filed https://github.com/apache/incubator-kie-drools/issues/6246 an will work on a fix.
Btw, as you are migrating from Drools 6.5, I think "Property Reactivity" is a caveat.
Property reactivity was introduced since Drools 5.4, but it was not enabled by default. However, it’s enabled by default since Drools 7. It means you see that rules react differently when you upgrade the version as you see now (actually, it's also including the filed bug, though).
If you want the behaviour closer to Drools 6.5, disable the Property reactivity feature.
```java
System.setProperty("drools.propertySpecific", "DISABLED");
```
https://docs.drools.org/7.73.0.Final/drools-docs/html_single/#_property_reactivity_enabled_by_default
The issue you reported will also go away, because it's a bug in Property reactivity.
Note that disabling Property reactivity will cause an infinite loop in your reproducer, because rule "Set worker name" keeps activating itself. It would work the same if you run the reproducer with Drools 6.5. But I think your original rules have no problem with disabling Property reactivity, because they worked with 6.5 on your side.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas closed issue #6243: Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation)
URL: https://github.com/apache/incubator-kie-drools/issues/6243
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas commented on issue #6243:
URL: https://github.com/apache/incubator-kie-drools/issues/6243#issuecomment-2683940861
Closing as the issue is fixed by https://github.com/apache/incubator-kie-drools/issues/6246 and it will be included in `10.1.0`. Feel free to reopen this if you will hit this issue with 10.1+.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Rule execution inconsistency when a subclass overrides a getter (unexpected null property evaluation) [incubator-kie-drools]
Posted by "orit1992 (via GitHub)" <gi...@apache.org>.
orit1992 commented on issue #6243:
URL: https://github.com/apache/incubator-kie-drools/issues/6243#issuecomment-2670831126
Hi @tkobayas, thanks for the response, your suggestion about disabling Property reactivity resolved the issue.
I have one more question: do you have any indication of which major version the fix might be included in?
Thanks again for your support!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org