Avoid NullReferenceExeption in GetTextFromQuery #346
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #344.
In rare cases, a thread-scheduling race condition can cause a thread's state to be ThreadState.Stopped even though it hasn't yet executed its
finally
block, which can result in result.StandardOutput or Error not being assigned a string, leaving them null. Furthermore, the C# docs say not to depend on ThreadState for synchronizing thread activity. So instead we check for the thread having ended by seeing whether thefinally
block has assigned a value to its Results property; until then, Results is null.This should guarantee the safety of the existing GetTextFromQuery code, but to be safe we also make sure it can turn null into an empty string.
This change is