mike-lischke / antlr4-c3

A grammar agnostic code completion engine for ANTLR4 based parsers
MIT License
396 stars 62 forks source link

Java port-> NPE happen when followSets contains FollowSetWithPath with null following member #108

Closed rovo98 closed 5 months ago

rovo98 commented 5 months ago

Description

When the showResult=true and logging is enabled, CodeCompletionCore will print some information after finishing collectionCandidates. According to the current code implementation,

https://github.com/mike-lischke/antlr4-c3/blob/60f62a4f4e39644280c8b666394bd8cf3cebb348/ports/java/src/main/java/com/vmware/antlr4c3/CodeCompletionCore.java#L218-L228

this might occurs NPE at the line 221 since the collected candidates.tokens might contains null values which come from the collected followingSets.

https://github.com/mike-lischke/antlr4-c3/blob/60f62a4f4e39644280c8b666394bd8cf3cebb348/ports/java/src/main/java/com/vmware/antlr4c3/CodeCompletionCore.java#L337-L343

https://github.com/mike-lischke/antlr4-c3/blob/60f62a4f4e39644280c8b666394bd8cf3cebb348/ports/java/src/main/java/com/vmware/antlr4c3/CodeCompletionCore.java#L361-L365

The above followingSet which contains null following might be put into the candidates.tokens:

https://github.com/mike-lischke/antlr4-c3/blob/60f62a4f4e39644280c8b666394bd8cf3cebb348/ports/java/src/main/java/com/vmware/antlr4c3/CodeCompletionCore.java#L456

I'm willing to draft a pr to fix this issue. 😊

mike-lischke commented 5 months ago

Great! Let's continue in the PR.