From 2f0029a04056a19359ed4336273f1a3a790f4c50 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 18 Jul 2012 15:04:05 -0500 Subject: [PATCH] Improved handling of (potentially) null fields --- .../Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java | 3 ++- runtime/Java/src/org/antlr/v4/runtime/Lexer.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java index fe47fc69a..dad26c7e5 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java @@ -126,7 +126,8 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { // lastErrorIndex+ // ", states="+lastErrorStates); if ( lastErrorIndex==recognizer.getInputStream().index() && - lastErrorStates.contains(recognizer._ctx.s) ) { + lastErrorStates != null && + lastErrorStates.contains(recognizer._ctx.s) ) { // uh oh, another error at same token index and previously-visited // state in ATN; must be a case where LT(1) is in the recovery // token set so nothing got consumed. Consume a single token diff --git a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java index b8dd57863..34b2fe426 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java @@ -130,6 +130,10 @@ public abstract class Lexer extends Recognizer */ @Override public Token nextToken() { + if (_input == null) { + throw new IllegalStateException("nextToken requires a non-null input stream."); + } + if (_hitEOF) { emitEOF(); return _token;