Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 1afced6

Browse files
committed
Fix NRE when calling Refresh() before static type initializers
1 parent f39f081 commit 1afced6

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/ServiceStack.Text/Json/JsonReader.Generic.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static JsonReader()
5050

5151
public static void Refresh()
5252
{
53+
if (JsonReader.Instance == null)
54+
return;
55+
5356
ReadFn = JsonReader.Instance.GetParseFn<T>();
5457
}
5558

src/ServiceStack.Text/Json/JsonWriter.Generic.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ public static void Reset()
154154

155155
public static void Refresh()
156156
{
157-
CacheFn = typeof (T) == typeof (object)
157+
if (JsonWriter.Instance == null)
158+
return;
159+
160+
CacheFn = typeof(T) == typeof(object)
158161
? JsonWriter.WriteLateBoundObject
159162
: JsonWriter.Instance.GetWriteFn<T>();
160163
}

src/ServiceStack.Text/Jsv/JsvReader.Generic.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static JsvReader()
5050

5151
public static void Refresh()
5252
{
53+
if (JsvReader.Instance == null)
54+
return;
55+
5356
ReadFn = JsvReader.Instance.GetParseFn<T>();
5457
}
5558

src/ServiceStack.Text/Jsv/JsvWriter.Generic.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public static void Reset()
112112

113113
public static void Refresh()
114114
{
115-
CacheFn = typeof (T) == typeof (object)
115+
if (JsvWriter.Instance == null)
116+
return;
117+
118+
CacheFn = typeof(T) == typeof(object)
116119
? JsvWriter.WriteLateBoundObject
117120
: JsvWriter.Instance.GetWriteFn<T>();
118121
}

0 commit comments

Comments
 (0)