apache / incubator-kie-drools

Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.
http://www.drools.org
Apache License 2.0
5.88k stars 2.5k forks source link

[new-parser] Error processing `@duration` for TypeDeclaration #5900

Closed yurloc closed 6 months ago

yurloc commented 6 months ago

Parent issue

Failing tests

Notes

I did some preliminary investigation and I think the problem is in the FQN of the event class (EventB). It seems like it's incorrectly prefixed with defaultpkg, therefore the MVELExprAnalyzer fails to load the class and read the duration accessor.

Rule code snippet

            drlBuilder.append(" import " + EventA.class.getCanonicalName() + ";\n");
            drlBuilder.append(" import " + EventB.class.getCanonicalName() + ";\n");
            drlBuilder.append(" declare " + EventA.class.getName() + " @role( event ) @duration(duration) end");
            drlBuilder.append(" declare " + EventB.class.getName() + " @role( event ) @duration(duration) end");
            drlBuilder.append(" rule R" + i + " when \n");
            drlBuilder.append("   $event1: " + EventA.class.getName() + "()\n");
            drlBuilder.append("   $event2: " + EventB.class.getName() + "(this != $event1, this after [1,10] $event1)\n");
            drlBuilder.append( "then end\n" );

Error output

### parse : ANTLR4_PARSER_ENABLED = true
09:42:34.157 [Time-limited test] ERROR o.d.c.k.b.impl.AbstractKieProject.buildKnowledgePackages:280 - Unable to build KieBaseModel:defaultKieBase
Error processing @duration for TypeDeclaration 'defaultpkg.org.drools.testcoverage.common.model.org.drools.testcoverage.common.model.EventB': cannot access the field 'duration'
Error processing @duration for TypeDeclaration 'defaultpkg.org.drools.testcoverage.common.model.org.drools.testcoverage.common.model.EventA': cannot access the field 'duration'

java.lang.RuntimeException: [Message [id=1, kieBase=defaultKieBase, level=ERROR, path=null, line=-1, column=0
   text=Error processing @duration for TypeDeclaration 'defaultpkg.org.drools.testcoverage.common.model.org.drools.testcoverage.common.model.EventB': cannot access the field 'duration'], Message [id=2, kieBase=defaultKieBase, level=ERROR, path=null, line=-1, column=0
   text=Error processing @duration for TypeDeclaration 'defaultpkg.org.drools.testcoverage.common.model.org.drools.testcoverage.common.model.EventA': cannot access the field 'duration']]

    at org.kie.internal.utils.KieHelper.getKieContainer(KieHelper.java:127)
    at org.kie.internal.utils.KieHelper.getKieContainer(KieHelper.java:119)
    at org.kie.internal.utils.KieHelper.build(KieHelper.java:79)
    at org.drools.testcoverage.regression.FusionAfterBeforeTest.testExpireEventsWhenSharingAllRules(FusionAfterBeforeTest.java:136)