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

@@ -229,7 +229,8 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
} }
// get number of characters in the last line // 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( return new BatchDefinition(
batchText, batchText,
@@ -263,7 +264,8 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
} }
// get number of characters in the last line // 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 //lineOffset doesn't matter because its the last batch
return Tuple.Create(endLine, endColumn); return Tuple.Create(endLine, endColumn);