handle null ref exceptions in managed parser (#1606)

* handle null ref exceptions

* add comment
This commit is contained in:
Alan Ren
2022-07-27 18:35:54 -07:00
committed by GitHub
parent 46e3c5270e
commit bfa40e86e4

View File

@@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
}
// Generate the rest batch definitions
for (int index = 1; index < count - 1 ; index++)
for (int index = 1; index < count - 1; index++)
{
lineDifference = batchInfos[index + 1].startLine - batchInfos[index].startLine;
position = ReadLines(reader, lineDifference, endLine);
@@ -151,7 +151,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
while (!foundAllOffsets)
{
// go until the last start line of the batches
for (int i = 0; i <= maxStartLine ; i++)
for (int i = 0; i <= maxStartLine; i++)
{
// get offset for the current batch
ReadLines(reader, ref count, ref offset, ref foundAllOffsets, batchInfos, offsets, i);
@@ -229,7 +229,8 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
}
// get number of characters in the last line
int endColumn = prevLine.ToCharArray().Length;
// for some SQLCMD scenarios, the reader is already at the end of file and causing the prevLine to be null.
int endColumn = prevLine == null ? 0 : prevLine.ToCharArray().Length;
return new BatchDefinition(
batchText,
@@ -263,7 +264,8 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
}
// get number of characters in the last line
int endColumn = prevLine.ToCharArray().Length;
// for some SQLCMD scenarios, the reader is already at the end of file and causing the prevLine to be null.
int endColumn = prevLine == null ? 0 : prevLine.ToCharArray().Length;
//lineOffset doesn't matter because its the last batch
return Tuple.Create(endLine, endColumn);