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

NullPointerException when adding an element to a collection inside rule method #23

Open
ghost opened this issue Feb 5, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 5, 2015

When adding an element to a collection inside a method that creates a rule, a NullPointerException occurs during "createParser".

Example:

package test;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.parboiled.Parboiled;
import org.parboiled.Rule;
import org.parboiled.support.Var;

import com.github.parboiled1.grappa.parsers.EventBusParser;

public class NpeOnMap {

    public static void main(String[] args) {
        TestParser parser = Parboiled.createParser(TestParser.class);
    }

    public static class TestParser extends EventBusParser<String> {

        Rule relativity() {
            final Map<String, String> map = new LinkedHashMap<>();
//          map.put("x", "y"); // NPE
            final List<String> list = new LinkedList<>();
//          list.add("x"); // NPE
            Var<String> m = new Var<>();
            return sequence("a", m.set(match()));
//          return sequence("a", "b"); // No NPE in any case
        }

    }

}

The NPE only occurs when using "match()" inside the returned rule. If no "match()" is used, then any other code works fine.

StackTrace:

Exception in thread "main" java.lang.RuntimeException: Error creating extended parser class: null
    at org.parboiled.Parboiled.createParser(Parboiled.java:75)
    at test.NpeOnMap.main(NpeOnMap.java:17)
Caused by: java.lang.NullPointerException
    at org.parboiled.transform.process.ImplicitActionsConverter.getDependents(ImplicitActionsConverter.java:180)
    at org.parboiled.transform.process.ImplicitActionsConverter.isImplicitAction(ImplicitActionsConverter.java:110)
    at org.parboiled.transform.process.ImplicitActionsConverter.walkNode(ImplicitActionsConverter.java:83)
    at org.parboiled.transform.process.ImplicitActionsConverter.walkNode(ImplicitActionsConverter.java:92)
    at org.parboiled.transform.process.ImplicitActionsConverter.walkNode(ImplicitActionsConverter.java:92)
    at org.parboiled.transform.process.ImplicitActionsConverter.process(ImplicitActionsConverter.java:73)
    at org.parboiled.transform.ParserTransformer.runMethodTransformers(ParserTransformer.java:122)
    at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:98)
    at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:66)
    at org.parboiled.Parboiled.createParser(Parboiled.java:67)
    ... 1 more
@fge
Copy link
Owner

fge commented May 15, 2015

This is due to an incorrect gathering of arguments when building the rule.

Fixing that will be quite a chore to do... Delaying to 2.2.

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