diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java index 0e57bae5e..2ebff1129 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java @@ -470,6 +470,10 @@ public class ATNConfigSet implements Set { configLookup.clear(); } + public boolean isReadonly() { + return readonly; + } + public void setReadonly(boolean readonly) { this.readonly = readonly; configLookup = null; // can't mod, no need for lookup cache diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 2489b05d1..098ed860d 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -1572,8 +1572,10 @@ public class ParserATNSimulator extends ATNSimulator { if ( existing!=null ) return existing; D.stateNumber = dfa.states.size(); - D.configs.optimizeConfigs(this); - D.configs.setReadonly(true); + if (!D.configs.isReadonly()) { + D.configs.optimizeConfigs(this); + D.configs.setReadonly(true); + } dfa.states.put(D, D); if ( debug ) System.out.println("adding new DFA state: "+D); return D;