Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new-parser] Accumulate parsed incorrectly if init and action statements are empty #5909

Closed
yurloc opened this issue May 8, 2024 · 2 comments
Assignees

Comments

@yurloc
Copy link
Contributor

yurloc commented May 8, 2024

Parent issue

Failing tests

  • org.drools.compiler.integrationtests.AccumulateTest#testAccumulateReturningNull

Notes

The error message is not very helpful but the stack trace is. This line is important:

at org.drools.model.codegen.execmodel.generator.visitor.ModelGeneratorVisitor.visit(ModelGeneratorVisitor.java:132)

In debug mode and a break point on this line, it can be observed that the patternSource is actually a FromDesr, and not an AccumulateDescr as expected. The empty init() and action() statements are incompliant with the fromAccumulate parser rule and so the parser is forced to recognize this accumulate statement using fromExpression.

Rule code snippet

        $totalAmount : Number() from accumulate( Cheese( $price : price ),
                                                 init( ),
                                                 action( ),
                                                 result( null ) );

Error output


### parse : ANTLR4_PARSER_ENABLED = true

com.github.javaparser.ParseProblemException: Encountered unexpected token: ":" ":"
    at line 1, column 28.

Was expecting one of:

    "!="
    "%"
    "%="
    "&"
    "&&"
    "&="
    "("
    ")"
    "*"
    "*="
    "+"
    "+="
    ","
    "-"
    "-="
    "->"
    "/"
    "/="
    "::"
    "<"
    "<<="
    "<="
    "="
    "=="
    ">"
    ">="
    ">>="
    ">>>="
    "?"
    "^"
    "^="
    "instanceof"
    "|"
    "|="
    "||"

Problem stacktrace : 
  org.drools.mvel.parser.GeneratedMvelParser.generateParseException(GeneratedMvelParser.java:16175)
  org.drools.mvel.parser.GeneratedMvelParser.jj_consume_token(GeneratedMvelParser.java:16017)
  org.drools.mvel.parser.GeneratedMvelParser.Arguments(GeneratedMvelParser.java:5288)
  org.drools.mvel.parser.GeneratedMvelParser.PrimaryPrefix(GeneratedMvelParser.java:4929)
  org.drools.mvel.parser.GeneratedMvelParser.PrimaryExpression(GeneratedMvelParser.java:4640)
  org.drools.mvel.parser.GeneratedMvelParser.PostfixExpression(GeneratedMvelParser.java:4504)
  org.drools.mvel.parser.GeneratedMvelParser.UnaryExpressionNotPlusMinus(GeneratedMvelParser.java:4474)
  org.drools.mvel.parser.GeneratedMvelParser.DrlxExpressionSwitch(GeneratedMvelParser.java:4375)
  org.drools.mvel.parser.GeneratedMvelParser.HalfBinaryExpression(GeneratedMvelParser.java:4310)
  org.drools.mvel.parser.GeneratedMvelParser.UnaryExpression(GeneratedMvelParser.java:4201)
  org.drools.mvel.parser.GeneratedMvelParser.MultiplicativeExpression(GeneratedMvelParser.java:4102)
  org.drools.mvel.parser.GeneratedMvelParser.AdditiveExpression(GeneratedMvelParser.java:4054)
  org.drools.mvel.parser.GeneratedMvelParser.ShiftExpression(GeneratedMvelParser.java:4009)
  org.drools.mvel.parser.GeneratedMvelParser.RelationalExpression(GeneratedMvelParser.java:3949)
  org.drools.mvel.parser.GeneratedMvelParser.InstanceOfExpression(GeneratedMvelParser.java:3868)
  org.drools.mvel.parser.GeneratedMvelParser.EqualityExpression(GeneratedMvelParser.java:3798)
  org.drools.mvel.parser.GeneratedMvelParser.AndExpression(GeneratedMvelParser.java:3753)
  org.drools.mvel.parser.GeneratedMvelParser.ExclusiveOrExpression(GeneratedMvelParser.java:3713)
  org.drools.mvel.parser.GeneratedMvelParser.InclusiveOrExpression(GeneratedMvelParser.java:3673)
  org.drools.mvel.parser.GeneratedMvelParser.ConditionalAndExpression(GeneratedMvelParser.java:3633)
  org.drools.mvel.parser.GeneratedMvelParser.ConditionalOrExpression(GeneratedMvelParser.java:3588)
  org.drools.mvel.parser.GeneratedMvelParser.ConditionalExpression(GeneratedMvelParser.java:3556)
  org.drools.mvel.parser.GeneratedMvelParser.Expression(GeneratedMvelParser.java:3360)
  org.drools.mvel.parser.GeneratedMvelParser.ArgumentList(GeneratedMvelParser.java:5302)
  org.drools.mvel.parser.GeneratedMvelParser.Arguments(GeneratedMvelParser.java:5284)
  org.drools.mvel.parser.GeneratedMvelParser.PrimaryPrefix(GeneratedMvelParser.java:4929)
  org.drools.mvel.parser.GeneratedMvelParser.PrimaryExpression(GeneratedMvelParser.java:4640)
  org.drools.mvel.parser.GeneratedMvelParser.PostfixExpression(GeneratedMvelParser.java:4504)
  org.drools.mvel.parser.GeneratedMvelParser.UnaryExpressionNotPlusMinus(GeneratedMvelParser.java:4474)
  org.drools.mvel.parser.GeneratedMvelParser.DrlxExpressionSwitch(GeneratedMvelParser.java:4375)
  org.drools.mvel.parser.GeneratedMvelParser.HalfBinaryExpression(GeneratedMvelParser.java:4310)
  org.drools.mvel.parser.GeneratedMvelParser.UnaryExpression(GeneratedMvelParser.java:4201)
  org.drools.mvel.parser.GeneratedMvelParser.MultiplicativeExpression(GeneratedMvelParser.java:4102)
  org.drools.mvel.parser.GeneratedMvelParser.AdditiveExpression(GeneratedMvelParser.java:4054)
  org.drools.mvel.parser.GeneratedMvelParser.ShiftExpression(GeneratedMvelParser.java:4009)
  org.drools.mvel.parser.GeneratedMvelParser.RelationalExpression(GeneratedMvelParser.java:3949)
  org.drools.mvel.parser.GeneratedMvelParser.InstanceOfExpression(GeneratedMvelParser.java:3868)
  org.drools.mvel.parser.GeneratedMvelParser.EqualityExpression(GeneratedMvelParser.java:3798)
  org.drools.mvel.parser.GeneratedMvelParser.AndExpression(GeneratedMvelParser.java:3753)
  org.drools.mvel.parser.GeneratedMvelParser.ExclusiveOrExpression(GeneratedMvelParser.java:3713)
  org.drools.mvel.parser.GeneratedMvelParser.InclusiveOrExpression(GeneratedMvelParser.java:3673)
  org.drools.mvel.parser.GeneratedMvelParser.ConditionalAndExpression(GeneratedMvelParser.java:3633)
  org.drools.mvel.parser.GeneratedMvelParser.ConditionalOrExpression(GeneratedMvelParser.java:3588)
  org.drools.mvel.parser.GeneratedMvelParser.ConditionalExpression(GeneratedMvelParser.java:3556)
  org.drools.mvel.parser.GeneratedMvelParser.Expression(GeneratedMvelParser.java:3360)
  org.drools.mvel.parser.GeneratedMvelParser.DrlxExpression(GeneratedMvelParser.java:8707)
  org.drools.mvel.parser.DrlxParser.lambda$static$0(DrlxParser.java:40)
  org.drools.mvel.parser.MvelParser.parse(MvelParser.java:140)
  org.drools.mvel.parser.DrlxParser.simplifiedParse(DrlxParser.java:54)
  org.drools.mvel.parser.DrlxParser.parseExpression(DrlxParser.java:50)
  org.drools.model.codegen.execmodel.generator.DrlxParseUtil.parseExpression(DrlxParseUtil.java:688)
  org.drools.model.codegen.execmodel.generator.visitor.FromVisitor.createSingleFrom(FromVisitor.java:91)
  org.drools.model.codegen.execmodel.generator.visitor.FromVisitor.visit(FromVisitor.java:80)
  java.base/java.util.Optional.flatMap(Optional.java:289)
  org.drools.model.codegen.execmodel.generator.visitor.pattern.ClassPatternDSL.buildFromDeclaration(ClassPatternDSL.java:153)
  org.drools.model.codegen.execmodel.generator.visitor.pattern.ClassPatternDSL.initPattern(ClassPatternDSL.java:96)
  org.drools.model.codegen.execmodel.generator.visitor.pattern.PatternDSL.buildPattern(PatternDSL.java:57)
  org.drools.model.codegen.execmodel.generator.visitor.ModelGeneratorVisitor.visit(ModelGeneratorVisitor.java:132)
  org.drools.drl.ast.descr.PatternDescr.accept(PatternDescr.java:278)
  org.drools.model.codegen.execmodel.generator.visitor.AndVisitor.visit(AndVisitor.java:52)
  org.drools.model.codegen.execmodel.generator.visitor.ModelGeneratorVisitor.visit(ModelGeneratorVisitor.java:70)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRule(ModelGenerator.java:204)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRuleDescr(ModelGenerator.java:185)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRules(ModelGenerator.java:164)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.generateModel(ModelGenerator.java:130)
  org.drools.model.codegen.execmodel.processors.ModelGeneratorPhase.process(ModelGeneratorPhase.java:48)
  org.drools.compiler.builder.impl.processors.IteratingPhase.process(IteratingPhase.java:53)
  org.drools.model.codegen.execmodel.processors.ModelMainCompilationPhase.process(ModelMainCompilationPhase.java:104)
  org.drools.model.codegen.execmodel.ModelBuilderImpl.doSecondBuildStep(ModelBuilderImpl.java:114)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:125)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:109)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:274)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:220)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:84)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:285)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:251)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:208)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:147)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
  org.drools.testcoverage.common.util.KieUtil.buildAndInstallKieModuleIntoRepo(KieUtil.java:78)
  org.drools.testcoverage.common.util.KieUtil.buildAndInstallKieModuleIntoRepo(KieUtil.java:72)
  org.drools.testcoverage.common.util.KieUtil.getKieModuleFromResources(KieUtil.java:249)
  org.drools.testcoverage.common.util.KieUtil.getKieModuleFromResources(KieUtil.java:238)
  org.drools.testcoverage.common.util.KieBaseUtil.getKieBaseFromKieModuleFromResources(KieBaseUtil.java:102)
  org.drools.testcoverage.common.util.KieBaseUtil.getKieBaseFromKieModuleFromDrl(KieBaseUtil.java:115)
  org.drools.compiler.integrationtests.AccumulateTest.testAccumulateReturningNull(AccumulateTest.java:854)


	at org.drools.mvel.parser.DrlxParser.simplifiedParse(DrlxParser.java:58)
	at org.drools.mvel.parser.DrlxParser.parseExpression(DrlxParser.java:50)
	at org.drools.model.codegen.execmodel.generator.DrlxParseUtil.parseExpression(DrlxParseUtil.java:688)
	at org.drools.model.codegen.execmodel.generator.visitor.FromVisitor.createSingleFrom(FromVisitor.java:91)
	at org.drools.model.codegen.execmodel.generator.visitor.FromVisitor.visit(FromVisitor.java:80)
	at java.base/java.util.Optional.flatMap(Optional.java:289)
	at org.drools.model.codegen.execmodel.generator.visitor.pattern.ClassPatternDSL.buildFromDeclaration(ClassPatternDSL.java:153)
	at org.drools.model.codegen.execmodel.generator.visitor.pattern.ClassPatternDSL.initPattern(ClassPatternDSL.java:96)
	at org.drools.model.codegen.execmodel.generator.visitor.pattern.PatternDSL.buildPattern(PatternDSL.java:57)
	at org.drools.model.codegen.execmodel.generator.visitor.ModelGeneratorVisitor.visit(ModelGeneratorVisitor.java:132)
	at org.drools.drl.ast.descr.PatternDescr.accept(PatternDescr.java:278)
	at org.drools.model.codegen.execmodel.generator.visitor.AndVisitor.visit(AndVisitor.java:52)
	at org.drools.model.codegen.execmodel.generator.visitor.ModelGeneratorVisitor.visit(ModelGeneratorVisitor.java:70)
	at org.drools.model.codegen.execmodel.generator.ModelGenerator.processRule(ModelGenerator.java:204)
	at org.drools.model.codegen.execmodel.generator.ModelGenerator.processRuleDescr(ModelGenerator.java:185)
	at org.drools.model.codegen.execmodel.generator.ModelGenerator.processRules(ModelGenerator.java:164)
	at org.drools.model.codegen.execmodel.generator.ModelGenerator.generateModel(ModelGenerator.java:130)
	at org.drools.model.codegen.execmodel.processors.ModelGeneratorPhase.process(ModelGeneratorPhase.java:48)
	at org.drools.compiler.builder.impl.processors.IteratingPhase.process(IteratingPhase.java:53)
	at org.drools.model.codegen.execmodel.processors.ModelMainCompilationPhase.process(ModelMainCompilationPhase.java:104)
	at org.drools.model.codegen.execmodel.ModelBuilderImpl.doSecondBuildStep(ModelBuilderImpl.java:114)
	at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:125)
	at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:109)
	at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:274)
	at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:220)
	at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:84)
	at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:285)
	at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:251)
	at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:208)
	at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:147)
	at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
	at org.drools.testcoverage.common.util.KieUtil.buildAndInstallKieModuleIntoRepo(KieUtil.java:78)
	at org.drools.testcoverage.common.util.KieUtil.buildAndInstallKieModuleIntoRepo(KieUtil.java:72)
	at org.drools.testcoverage.common.util.KieUtil.getKieModuleFromResources(KieUtil.java:249)
	at org.drools.testcoverage.common.util.KieUtil.getKieModuleFromResources(KieUtil.java:238)
	at org.drools.testcoverage.common.util.KieBaseUtil.getKieBaseFromKieModuleFromResources(KieBaseUtil.java:102)
	at org.drools.testcoverage.common.util.KieBaseUtil.getKieBaseFromKieModuleFromDrl(KieBaseUtil.java:115)
	at org.drools.compiler.integrationtests.AccumulateTest.testAccumulateReturningNull(AccumulateTest.java:854)
@tkobayas
Copy link
Contributor

/take

@tkobayas
Copy link
Contributor

Fixed by #5965

@github-project-automation github-project-automation bot moved this from 📋 Backlog to 🎯 Done in 🦉 KIE Podling Board May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎯 Done
Development

No branches or pull requests

2 participants