Matteo Casalino created DROOLS-5560:
---------------------------------------
Summary: ClassCastException on Fact Attribute Set After UpdateToVersion
Key: DROOLS-5560
URL:
https://issues.redhat.com/browse/DROOLS-5560
Project: Drools
Issue Type: Bug
Components: core engine
Affects Versions: 7.41.0.Final
Reporter: Matteo Casalino
Assignee: Mario Fusco
Attachments: class-cast-exception-on-fact-attribute-set-after-update.zip
After updating a KieContainer with a change in a fact type _UnreferencedType_, if
instances of another unrelated fact type _ReferencedType_ are modified in a rule, then
setting any field of _ReferencedType_ through the _FactType_ API will throw a
_ClassCastException_:
{noformat}
java.lang.ClassCastException: class org.example.facts.ReferencedType cannot be cast to
class org.example.facts.ReferencedType (org.example.facts.ReferencedType is in unnamed
module of loader
org.drools.dynamic.DynamicProjectClassLoader$DefaultInternalTypesClassLoader @59901c4d;
org.example.facts.ReferencedType is in unnamed module of loader
org.drools.dynamic.DynamicProjectClassLoader$DefaultInternalTypesClassLoader @5e1fc2aa)
at org.drools.base.org.example.facts.ReferencedType1921143808$setStr.setValue(Unknown
Source)
at org.drools.core.base.ClassFieldWriter.setValue(ClassFieldWriter.java:164)
at org.drools.core.base.ClassFieldAccessor.setValue(ClassFieldAccessor.java:246)
at org.drools.core.factmodel.ClassDefinition.set(ClassDefinition.java:278)
at
org.example.reproducer.FactTypeUpdateTest.testUpdateThenSetFactAttribute(FactTypeUpdateTest.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58){noformat}
Below the example DRL that triggers the issue.
Initial DRL:
{noformat}
package org.example.facts
declare ReferencedType
str : String
end
declare UnreferencedType
x : int
end
package org.example.rules
import org.example.facts.*;
rule "rule updating ReferencedType"
"when
$x : ReferencedType( )
then
$x.setStr("foo");
update($x);
end{noformat}
Updated DRL:
{noformat}
package org.example.facts
declare ReferencedType
str : String
end
declare UnreferencedType
x : int
y : String // NEW ATTRIBUTE ADDED HERE
end
package org.example.rules
import org.example.facts.*;
rule "rule updating ReferencedType"
"when
$x : ReferencedType( )
then
$x.setStr("foo");
update($x);
end{noformat}
Throwing code example:
{noformat}
updateToVersion(); // Updates the KieContainer
KieBase kiebase = kieContainer.getKieBase("ExampleKiebase");
FactType referencedType = kiebase.getFactType("org.example.facts",
"ReferencedType");
Object instance = referencedType.newInstance();
referencedType.set(instance, "str", "bar"); // Throws
ClassCastException{noformat}
This is similar to DROOLS-5449, but in this case we instantiate the fact from the updated
fact type, so we believe that there is no API misuse.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)