From: Benjamin Bartels Date: Thu, 18 Apr 2019 12:53:22 +0000 (+0100) Subject: Fixed ChunkEnumerator.Current NRE (#24076) X-Git-Tag: accepted/tizen/unified/20190813.215958~46^2~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4111fae1ce185de69d1bf532503b5d369f2a5c53;p=platform%2Fupstream%2Fcoreclr.git Fixed ChunkEnumerator.Current NRE (#24076) * Fixed ChunkEnumerator.Current NRE * Added Nullable Flow analysis annotation comment * Changed TODO-NULLABLE comment to link to appropriate issue --- diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index b694b7d..eee36e5 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 /// /// Implements the IEnumerator pattern. /// - public ReadOnlyMemory Current => new ReadOnlyMemory(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: NullReferenceException if called before calling MoveNext + public ReadOnlyMemory Current + { + get + { + if (_currentChunk == null) + { + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); + } + + return new ReadOnlyMemory(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: https://github.com/dotnet/csharplang#538 + } + } #region private internal ChunkEnumerator(StringBuilder stringBuilder)