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

showAllPhraseInterpretations fails with NullPointerException #258

Closed
WolfgangFahl opened this issue Apr 8, 2016 · 1 comment
Closed

Comments

@WolfgangFahl
Copy link

With the grammar from ANTLR Issue 994
antlr/antlr4#994

and testing expr with input
a and b or b and not c

clicking the read ambiguity line and right clicking "show all phrase interpretations"

    at org.antlr.v4.runtime.tree.Trees.findNodeSuchThat(Trees.java:270)
    at org.antlr.intellij.plugin.parsing.ParsingUtils.findOverriddenDecisionRoot(ParsingUtils.java:565)
    at org.antlr.intellij.plugin.preview.ShowAmbigTreesDialog.setTrees(ShowAmbigTreesDialog.java:228)
    at org.antlr.intellij.plugin.preview.ShowAmbigTreesDialog.popupAmbigTreesDialog(ShowAmbigTreesDialog.java:127)
    at org.antlr.intellij.plugin.preview.ShowAmbigTreesDialog$3.run(ShowAmbigTreesDialog.java:84)``` 
@WolfgangFahl
Copy link
Author

the Context tree ctx is null because the following code might provide null trees as part of the result list:

public static List<ParserRuleContext> getAllPossibleParseTrees(Grammar g, Parser originalParser, TokenStream tokens, int decision, BitSet alts, int startIndex, int stopIndex, int startRuleIndex) throws RecognitionException {
        ArrayList trees = new ArrayList();
        ParserInterpreter parser = deriveTempParserInterpreter(g, originalParser, tokens);

        for(int alt = alts.nextSetBit(0); alt >= 0; alt = alts.nextSetBit(alt + 1)) {
            parser.reset();
            parser.addDecisionOverride(decision, startIndex, alt);
            ParserRuleContext t = parser.parse(startRuleIndex);
            GrammarInterpreterRuleContext ambigSubTree = (GrammarInterpreterRuleContext)Trees.getRootOfSubtreeEnclosingRegion(t, startIndex, stopIndex);
            if(Trees.isAncestorOf(parser.getOverrideDecisionRoot(), ambigSubTree)) {
                ambigSubTree = (GrammarInterpreterRuleContext)parser.getOverrideDecisionRoot();
            }

            trees.add(ambigSubTree);
        }

        return trees;

there should IMHO be a check that ambigSubTree is not null before adding it ... at https://github.com/antlr/antlr4/blob/master/tool/src/org/antlr/v4/tool/GrammarParserInterpreter.java#L323

@parrt parrt closed this as completed in 86c2d95 Jun 4, 2016
parrt added a commit that referenced this issue Jun 4, 2016
Fixes #255, Fixes #258; dup antlr functions to fix 2 different bugs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant