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] Rule Compilation error Cannot invoke charAt(int) on the primitive type char #5867

Closed yurloc closed 6 months ago

yurloc commented 6 months ago

Parent issue

Failing tests

Notes

The compilation error seems valid. The question is why the old parser accepts this.

Rule code snippet

then
    if ( c0 != Character.valueOf('\u0000'.charAt(0)) ) list.add( " hard char default value != '\u0000' <" + c0 + ">");

Error output

23:31:28.733 [main] WARN  o.d.c.k.builder.impl.KieBuilderImpl.packageNameForFile:396 - File 'org/drools/compiler/factmodel/traits/testTraitWrapping.drl' is in folder 'org/drools/compiler/factmodel/traits' but declares package 'org.drools.compiler.test'. It is advised to have a correspondance between package and folder names.
### parse : ANTLR4_PARSER_ENABLED = true
23:31:28.818 [main] ERROR o.d.c.k.b.impl.AbstractKieProject.buildKnowledgePackages:280 - Unable to build KieBaseModel:defaultKieBase
Rule Compilation error : [Rule name='TraitHard']
    Cannot invoke charAt(int) on the primitive type char

java.lang.RuntimeException: [Message [id=1, kieBase=defaultKieBase, level=ERROR, path=org/drools/compiler/factmodel/traits/testTraitWrapping.drl, line=70, column=0
   text=Rule Compilation error Cannot invoke charAt(int) on the primitive type char]]

    at org.kie.internal.utils.KieHelper.getKieContainer(KieHelper.java:127)
    at org.kie.internal.utils.KieHelper.build(KieHelper.java:89)
    at org.kie.internal.utils.KieHelper.build(KieHelper.java:84)
    at org.drools.traits.compiler.factmodel.traits.TraitTest.getSession(TraitTest.java:141)
    at org.drools.traits.compiler.factmodel.traits.TraitTest.traitMethodsWithObjects(TraitTest.java:324)
yurloc commented 6 months ago

Fixed by #5913.

Context: Character.valueOf('\u0000'.charAt(0)).

Before the fix:

parseTree

'\u0000'.charAt is incorrectly tokenized as RHS_CHUNK and so normalizeString is not applied.

After the fix:

parseTree

'\u0000'.charAt is correctly tokenized as RHS_STRING_LISTERAL and so it is normalized to "\u0000".