Skip to content

Commit 6bd67c0

Browse files
CopilotBornToBeRoot
andcommitted
Add null-safety checks for PolicyManager deserialization
Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
1 parent bafdcf3 commit 6bd67c0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Source/NETworkManager.Settings/PolicyManager.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,22 @@ public static void Load()
6868
Log.Info($"Loading system-wide policies from: {filePath}");
6969

7070
var jsonString = File.ReadAllText(filePath);
71-
Current = JsonSerializer.Deserialize<PolicyInfo>(jsonString, JsonOptions);
71+
72+
// Treat empty or JSON "null" as "no policies" instead of crashing
73+
if (string.IsNullOrWhiteSpace(jsonString))
74+
{
75+
Current = new PolicyInfo();
76+
Log.Info("Config file is empty, no system-wide policies loaded.");
77+
}
78+
else
79+
{
80+
Current = JsonSerializer.Deserialize<PolicyInfo>(jsonString, JsonOptions) ?? new PolicyInfo();
81+
82+
Log.Info("System-wide policies loaded successfully.");
7283

73-
Log.Info("System-wide policies loaded successfully.");
74-
75-
// Log enabled settings
76-
Log.Info($"System-wide policy - Update_CheckForUpdatesAtStartup: {Current.Update_CheckForUpdatesAtStartup?.ToString() ?? "Not set"}");
84+
// Log enabled settings
85+
Log.Info($"System-wide policy - Update_CheckForUpdatesAtStartup: {Current.Update_CheckForUpdatesAtStartup?.ToString() ?? "Not set"}");
86+
}
7787
}
7888
catch (Exception ex)
7989
{

0 commit comments

Comments
 (0)