[antlr-interest] Antlr-3.2 C# Target: RecognitionException.csConstructor Bug
sharwell at pixelminegames.com
Tue Dec 15 13:07:26 PST 2009
RecognitionException is the base class for syntactical exceptions found
by the generated parser. For other semantics exceptions, such as the
function call validation you're referring to, you should throw another
exception relevant to your compilation process (one not derived from
I'm going to update the constructor of RecognitionException to throw an
ArgumentNullException if `input` is null. This is part of my recent work
on validating parameters of all public-facing members inside the CSharp3
runtime. I'm using the static analysis tools of Code Contracts library
to make sure I cover everything without introducing any additional
references in the final binaries.
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of John Moses
Sent: Tuesday, December 15, 2009 1:38 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Antlr-3.2 C# Target:
I believe I'm running into a bug in the constructors of class
RecognitionException in the CSharp code of Antlr.Runtime.
5 of the 6 constructors of RecognitionException call this version (with
various parameters 'nulled' out):
public RecognitionException(string message, Exception inner,
3 of the 6 call the above constructor with null for the IIntStream input
parameter. Unfortunately, the 2nd line of this constructor is:
this.index = input.Index();
which immediately throws the infamous 'Object reference not set to an
instance of an object' exception (since input is null).
The most obvious way to encounter the bug is to throw a new
RecognitionException upon discovery of some
'otherwise-not-an-Antlr-exception' situation (like the number of
expressions in an expression_list doesn't match what a function call
throw new RecognitionException("Improper number of parameters in
(Just a simple example, in real life I do a better job of reporting an
error than this! :-)
My workaround is either:
1) Capture the IIntStream from earlier in the process and call a
throw new RecognitionException("Improper blah,
2) Throw an exception unrelated to RecognitionException.
But it should be easy to fix.
More information about the antlr-interest