tunnelvisionlabs / antlr4

The highly-optimized fork of ANTLR 4 (see README)
Other
73 stars 12 forks source link

ATN clearDFA() results in nullpointer exception #78

Open chandra-kambham opened 2 years ago

chandra-kambham commented 2 years ago
public final void clearDFA() {
        decisionToDFA = new DFA[decisionToState.size()];
        for (int i = 0; i < decisionToDFA.length; i++) {
            decisionToDFA[i] = new DFA(decisionToState.get(i), i);
        }

the clearDFA function of ATN.java first reinitializes the DFA array and then assigns the value to array elements, due to this when parallel parsers are in use, calling clearDFA from one parser results in getting nullpointer exception in multithreaded scenarios

java.lang.NullPointerException: null at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:367) ~[antlr4-runtime-4.9.0.jar:4.9.0] at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:357) ~[antlr4-runtime-4.9.0.jar:4.9.0]

From the ANTLR main release branch i can see the clearDFA logic is written without the reinitilization of DFA array.. so whether this is a bug in the optimized fork ?

public final void clearDFA() {
        for (int i = 0; i < decisionToDFA.length; i++) {
            decisionToDFA[i] = new DFA(decisionToState.get(i), i);
        }
chandra-kambham commented 2 years ago

@sharwell , i thought of customizing the clearDFA, but its defined as final method, any alternative way i can handle this issue without waiting for next release?