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

Closed
yurloc opened this issue Apr 24, 2024 · 1 comment

Comments

@yurloc
Copy link
Contributor

yurloc commented Apr 24, 2024

Parent issue

Failing tests

  • org.drools.traits.compiler.factmodel.traits.TraitTest#traitMethodsWithObjects

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
Copy link
Contributor Author

yurloc commented May 17, 2024

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".

@yurloc yurloc closed this as completed May 17, 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

1 participant