Skip to content
Prev Previous commit
Applying feedback
  • Loading branch information
buyaa-n committed Nov 22, 2019
commit 9d735b75bbff865a7afe83e346b9efbf9dd12d6c
2 changes: 1 addition & 1 deletion src/libraries/System.Text.Json/ref/System.Text.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public void Skip() { }
public bool TrySkip() { throw null; }
public bool ValueTextEquals(System.ReadOnlySpan<byte> utf8Text) { throw null; }
public bool ValueTextEquals(System.ReadOnlySpan<char> text) { throw null; }
public bool ValueTextEquals(string text) { throw null; }
public bool ValueTextEquals(string? text) { throw null; }
}
public sealed partial class Utf8JsonWriter : System.IAsyncDisposable, System.IDisposable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to the Utf8JsonWriter and related types look good.

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace System.Text.Json
public class JsonException : Exception
{
// Allow the message to mutate to avoid re-throwing and losing the StackTrace to an inner exception.
private string? _message;
internal string? _message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the nullablility flow changing this from private to internal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is kind of a long story. Exception.Message getter shouldn't be nullable (contract) so we changed the getter from return _message into return _message ?? base.Message;. But there is a logic in ThrowHelper set the message when Message is null set t https://github.com/dotnet/runtime/pull/114/files#diff-e586edfb9caf385bf493d49a97f197a7R217 which not setting correct message anymore after changing Message to non null. So instead of using Message property we changed it to use this field direclty ex._message; for which the field need to be internal


/// <summary>
/// Creates a new exception object to relay error information to the user.
Expand Down Expand Up @@ -134,7 +134,7 @@ public override string Message
{
get
{
return _message!;
return _message ?? base.Message;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ private protected JsonNode() { }
/// <exception cref="ArgumentException">
/// Provided <see cref="JsonElement"/> was not built from <see cref="JsonNode"/>.
/// </exception>
public static JsonNode GetNode(JsonElement jsonElement) => !jsonElement.IsImmutable ? (JsonNode)jsonElement._parent! : throw new ArgumentException(SR.NotNodeJsonElementParent);
public static JsonNode GetNode(JsonElement jsonElement)
{
if (jsonElement.IsImmutable)
{
throw new ArgumentException(SR.NotNodeJsonElementParent);
}
Debug.Assert(jsonElement._parent != null);
return (JsonNode)jsonElement._parent;
}

/// <summary>
/// Gets the <see cref="JsonNode"/> represented by the <paramref name="jsonElement"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.Text.Json
[Serializable]
internal sealed class JsonReaderException : JsonException
{
public JsonReaderException(string? message, long lineNumber, long bytePositionInLine) : base(message, path: null, lineNumber, bytePositionInLine)
public JsonReaderException(string message, long lineNumber, long bytePositionInLine) : base(message, path: null, lineNumber, bytePositionInLine)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public bool ValueTextEquals(ReadOnlySpan<byte> utf8Text)
/// if required. The look up text is matched as is, without any modifications to it.
/// </para>
/// </remarks>
public bool ValueTextEquals(string text)
public bool ValueTextEquals(string? text)
{
return ValueTextEquals(text.AsSpan());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void ThrowInvalidOperationException_SerializerDictionaryKeyNull(Ty
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ReThrowWithPath(in ReadStack readStack, JsonReaderException ex)
{
Debug.Assert(ex.Path == null && ex.Message != null);
Debug.Assert(ex.Path == null);

string path = readStack.JsonPath();
string message = ex.Message;
Expand Down Expand Up @@ -179,7 +179,7 @@ public static void AddExceptionInformation(in ReadStack readStack, in Utf8JsonRe
string path = readStack.JsonPath();
ex.Path = path;

string? message = ex.Message;
string? message = ex._message;

if (string.IsNullOrEmpty(message))
{
Expand Down Expand Up @@ -214,7 +214,7 @@ public static void AddExceptionInformation(in WriteStack writeStack, JsonExcepti
string path = writeStack.PropertyPath();
ex.Path = path;

string? message = ex.Message;
string? message = ex._message;
if (string.IsNullOrEmpty(message))
{
// Use a default message.
Expand Down