Class cast exception when adding item to data store
Closed this issue · 3 comments
8.44.0.Final
Java 17
I have a JUnit test class where I have been testing my rules and while doing that, I face no problems. The issue arises when I try to do the same in my application code. I am using the AWS Lambda environment and compiling into a fat jar using the maven kie plugin and shade.
In both test and application class I follow the same procedure as is shown in examples:
- Create my RuleUnitData object
- Add test data into data store
- Create a RuleUnitInstance with object
- Fire the rules
A ClassCastException gets thrown with the following message:
class org.drools.core.common.DefaultFactHandle cannot be cast to class org.drools.ruleunits.impl.facthandles.RuleUnitInternalFactHandle
Class and method where exception occurs:
ListDataStore
I saw that you are the author for a lot of the related code. Would you be able to help me with this? Let me know if I can share any more information that would be helpful. I hope to be able to use rule units in my project but this has been a blocker so far during deployment.
Thank you for your time!
Sorry @danielfain, but it's nearly impossible to me to investigate this issue without a reproducer or any further hints. My understanding is that you have a working unit test, but then when you try to deploy exactly the same thing on AWS lambda it fails in production with that ClassCastException
is that correct? If so what could be the differences between these 2 situations? Can you please share your project that is causing this problem or even better a simplified and isolated version of it?
I was writing a simplified version of my project to share with you and on my first attempt of uploading and testing on AWS, it worked perfectly. I then made some small changes (mostly formatting), recompiled, and uploaded again to AWS. On that test attempt, and any attempt going forward, I was met with the same ClassCastException that I had been getting at work. I was very confused at how small formatting tweaks could cause the issue so I reverted the code back to exactly how it was when it worked. Same issue.
At this point I am thinking it is probably something to do with the build. I find this maven shade warning:
[WARNING] drools-kiesession-8.44.0.Final.jar, drools-learning-1.0-SNAPSHOT.jar, drools-ruleunits-impl-8.44.0.Final.jar define 1 overlapping resource: [WARNING] - META-INF/services/org.drools.core.reteoo.RuntimeComponentFactory
I check the packaged jar and the META-INF file contains org.drools.kiesession.factory.RuntimeComponentFactoryImpl when (I believe) it should be set to org.drools.ruleunits.impl.factory.RuleUnitRuntimeComponentFactory.
I made that correction in resources/META-INF and now everything is working. I don't know how this happened or if there's anything to "fix" but thought I'd share in case anyone else comes across this issue.