diff --git a/Antlr4.Runtime/Atn/EmptyPredictionContext.cs b/Antlr4.Runtime/Atn/EmptyPredictionContext.cs index e3a9e63bf..86761986a 100644 --- a/Antlr4.Runtime/Atn/EmptyPredictionContext.cs +++ b/Antlr4.Runtime/Atn/EmptyPredictionContext.cs @@ -67,12 +67,12 @@ namespace Antlr4.Runtime.Atn public override PredictionContext GetParent(int index) { - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(); } public override int GetReturnState(int index) { - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(); } public override int FindReturnState(int returnState) diff --git a/Antlr4.Runtime/BufferedTokenStream.cs b/Antlr4.Runtime/BufferedTokenStream.cs index 61d1edfc4..0bc96bcbe 100644 --- a/Antlr4.Runtime/BufferedTokenStream.cs +++ b/Antlr4.Runtime/BufferedTokenStream.cs @@ -242,8 +242,8 @@ namespace Antlr4.Runtime { if (i < 0 || i >= tokens.Count) { - throw new IndexOutOfRangeException("token index " + i + " out of range 0.." + (tokens - .Count - 1)); + throw new ArgumentOutOfRangeException("token index " + i + " out of range 0.." + + (tokens.Count - 1)); } return tokens[i]; } @@ -386,7 +386,7 @@ namespace Antlr4.Runtime LazyInit(); if (start < 0 || stop >= tokens.Count || stop < 0 || start >= tokens.Count) { - throw new IndexOutOfRangeException("start " + start + " or stop " + stop + " not in 0.." + throw new ArgumentOutOfRangeException("start " + start + " or stop " + stop + " not in 0.." + (tokens.Count - 1)); } if (start > stop) @@ -494,8 +494,8 @@ namespace Antlr4.Runtime LazyInit(); if (tokenIndex < 0 || tokenIndex >= tokens.Count) { - throw new IndexOutOfRangeException(tokenIndex + " not in 0.." + (tokens.Count - 1 - )); + throw new ArgumentOutOfRangeException(tokenIndex + " not in 0.." + (tokens.Count + - 1)); } int nextOnChannel = NextTokenOnChannel(tokenIndex + 1, Lexer.DefaultTokenChannel); int to; @@ -539,8 +539,8 @@ namespace Antlr4.Runtime LazyInit(); if (tokenIndex < 0 || tokenIndex >= tokens.Count) { - throw new IndexOutOfRangeException(tokenIndex + " not in 0.." + (tokens.Count - 1 - )); + throw new ArgumentOutOfRangeException(tokenIndex + " not in 0.." + (tokens.Count + - 1)); } int prevOnChannel = PreviousTokenOnChannel(tokenIndex - 1, Lexer.DefaultTokenChannel ); diff --git a/Antlr4.Runtime/UnbufferedCharStream.cs b/Antlr4.Runtime/UnbufferedCharStream.cs index d690cf52c..328a5131b 100644 --- a/Antlr4.Runtime/UnbufferedCharStream.cs +++ b/Antlr4.Runtime/UnbufferedCharStream.cs @@ -282,7 +282,7 @@ namespace Antlr4.Runtime int index = p + i - 1; if (index < 0) { - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(); } if (index > n) { diff --git a/Antlr4.Runtime/UnbufferedTokenStream.cs b/Antlr4.Runtime/UnbufferedTokenStream.cs index 3b0d385ab..0363c27a4 100644 --- a/Antlr4.Runtime/UnbufferedTokenStream.cs +++ b/Antlr4.Runtime/UnbufferedTokenStream.cs @@ -147,7 +147,7 @@ namespace Antlr4.Runtime int bufferStartIndex = GetBufferStartIndex(); if (i < bufferStartIndex || i >= bufferStartIndex + n) { - throw new IndexOutOfRangeException("get(" + i + ") outside buffer: " + bufferStartIndex + throw new ArgumentOutOfRangeException("get(" + i + ") outside buffer: " + bufferStartIndex + ".." + (bufferStartIndex + n)); } return tokens[i - bufferStartIndex]; @@ -163,7 +163,7 @@ namespace Antlr4.Runtime int index = p + i - 1; if (index < 0) { - throw new IndexOutOfRangeException("LT(" + i + ") gives negative index"); + throw new ArgumentOutOfRangeException("LT(" + i + ") gives negative index"); } if (index >= n) { diff --git a/reference/sharpen-all-options.txt b/reference/sharpen-all-options.txt index b7cb7a646..9f7e7ff03 100644 --- a/reference/sharpen-all-options.txt +++ b/reference/sharpen-all-options.txt @@ -179,6 +179,7 @@ -typeMapping org.antlr.v4.runtime.misc.ParseCancellationException ParseCanceledException -typeMapping java.util.concurrent.CancellationException System.OperationCanceledException +-typeMapping java.lang.IndexOutOfBoundsException ArgumentOutOfRangeException -typeMapping org.antlr.v4.runtime.misc.Tuple System.Tuple -typeMapping org.antlr.v4.runtime.misc.Tuple2<,> System.Tuple