summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Bartels <bartels.benjamin@tutanota.de>2019-04-18 13:53:22 +0100
committerStephen Toub <stoub@microsoft.com>2019-04-18 08:53:22 -0400
commit4111fae1ce185de69d1bf532503b5d369f2a5c53 (patch)
treedbd21258e222ef13966a1dfe8acdbc682673b444 /src
parent837ac49c1ac46729df88ddb4a5d73ade6cc55cfc (diff)
downloadcoreclr-4111fae1ce185de69d1bf532503b5d369f2a5c53.tar.gz
coreclr-4111fae1ce185de69d1bf532503b5d369f2a5c53.tar.bz2
coreclr-4111fae1ce185de69d1bf532503b5d369f2a5c53.zip
Fixed ChunkEnumerator.Current NRE (#24076)
* Fixed ChunkEnumerator.Current NRE * Added Nullable Flow analysis annotation comment * Changed TODO-NULLABLE comment to link to appropriate issue
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
index b694b7d00c..eee36e52ec 100644
--- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
+++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
@@ -629,7 +629,18 @@ namespace System.Text
/// <summary>
/// Implements the IEnumerator pattern.
/// </summary>
- public ReadOnlyMemory<char> Current => new ReadOnlyMemory<char>(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: NullReferenceException if called before calling MoveNext
+ public ReadOnlyMemory<char> Current
+ {
+ get
+ {
+ if (_currentChunk == null)
+ {
+ ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
+ }
+
+ return new ReadOnlyMemory<char>(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: https://github.com/dotnet/csharplang#538
+ }
+ }
#region private
internal ChunkEnumerator(StringBuilder stringBuilder)