You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "yesamer (via GitHub)" <gi...@apache.org> on 2026/04/24 07:43:46 UTC
[PR] [NO-ISSUE] Fix flaky tests in drools-traits by preventing NPE in AbstractTraitFactory and improving error logging [incubator-kie-drools]
yesamer opened a new pull request, #6678:
URL: https://github.com/apache/incubator-kie-drools/pull/6678
Fixed flaky tests in drools-traits module by addressing NullPointerException in [`AbstractTraitFactory`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java) and improved error logging throughout the class.
## Problem
Five tests in `TraitTypeGenerationTest` were failing intermittently with:
```
java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Constructor.newInstance(Object[])" because "konst" is null
```
## Root Cause
The [`cacheConstructor()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:162) method could return `null` when [`buildProxyClass()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:196) failed to build the proxy class. However, [`getProxy()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:119) attempted to invoke `konst.newInstance()` without checking for null, causing NullPointerException.
## Changes Made
### 1. Null Safety Fix
- Added null check in [`getProxy()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:137) after the synchronized block
- Throws meaningful `LogicalTypeInconsistencyException` instead of allowing NPE
### 2. Enhanced Error Logging
Replaced generic "Exception" log messages with detailed, contextual error messages in all catch blocks:
- **[`getProxy()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:156)**: Separated exception handling for `InstantiationException`, `InvocationTargetException`, and `IllegalAccessException` with specific error messages including trait and core class names
- **[`cacheConstructor()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:183)**: Enhanced `NoSuchMethodException` logging with proxy class name, mode, trait, and core class information
- **[`buildProxyClass()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:243)**: Improved error messages for property wrapper and proxy class build failures with class names and early return on failure
- **[`buildProxyClass()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:276)**: Enhanced `ClassNotFoundException` logging with proxy and wrapper class names
- **[`getCoreWrapper()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:291)**: Separated `IOException` and `ClassNotFoundException` with specific messages
- **[`getCoreWrapper()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:299)**: Separated `InstantiationException`, `IllegalAccessException`, and `IOException` with descriptive messages
- **[`asTraitable()`](drools-traits/src/main/java/org/drools/traits/core/factmodel/AbstractTraitFactory.java:321)**: Enhanced `IOException` logging with core class name
--
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: [PR] [NO-ISSUE] Fix flaky tests in drools-traits by preventing NPE in AbstractTraitFactory and improving error logging [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer closed pull request #6678: [NO-ISSUE] Fix flaky tests in drools-traits by preventing NPE in AbstractTraitFactory and improving error logging
URL: https://github.com/apache/incubator-kie-drools/pull/6678
--
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