Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Converters;
using System.Text.Json.Serialization.Metadata;
using System.Threading;

namespace System.Text.Json
{
Expand All @@ -30,10 +31,10 @@ public sealed partial class JsonSerializerOptions
[RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)]
private void RootBuiltInConverters()
{
if (s_defaultSimpleConverters is null)
if (Volatile.Read(ref s_defaultFactoryConverters) is null)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know this could not be a direct backport. So I assume the comments in the main change do not apply here? https://github.com/dotnet/runtime/pull/66522/files#diff-143351693c2cb653ad82e34086cfd8863b0bda66c8b498ed8a400924c4f5224e

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They do, but this is fairly standard use of Volatile so I don't believe it warrants explanation.

{
s_defaultSimpleConverters = GetDefaultSimpleConverters();
s_defaultFactoryConverters = new JsonConverter[]
Volatile.Write(ref s_defaultFactoryConverters, new JsonConverter[]
Comment thread
jkotas marked this conversation as resolved.
{
// Check for disallowed types.
new UnsupportedTypeConverterFactory(),
Expand All @@ -48,7 +49,7 @@ private void RootBuiltInConverters()
new IEnumerableConverterFactory(),
// Object should always be last since it converts any type.
new ObjectConverterFactory()
};
});
}
}

Expand Down