Description
Several locations use Path.GetDirectoryName(...)! or fileInfo.Directory! with the null-forgiving operator, but these APIs can return null:
| File |
Line |
Code |
Risk |
src/Servy.Core/Helpers/ResourceHelper.cs |
228 |
Directory.CreateDirectory(targetPathDir!) |
ArgumentNullException crash |
src/Servy.Core/IO/RotatingStreamWriter.cs |
312 |
_file.Directory!.FullName |
NRE during log rotation |
src/Servy.Core/IO/RotatingStreamWriter.cs |
366 |
Path.GetDirectoryName(...)! |
NRE during log rotation |
src/Servy.Service/Helpers/ServiceHelper.cs |
255 |
Path.Combine(dir!, ...) |
NRE prevents service restart recovery |
Path.GetDirectoryName returns null for root paths. FileInfo.Directory returns null when constructed with a bare filename.
Severity
Warning — NRE crashes in log rotation and service recovery code paths.
Suggested fix
Add explicit null checks before using these values, with appropriate fallback behavior or error messages.
Description
Several locations use
Path.GetDirectoryName(...)!orfileInfo.Directory!with the null-forgiving operator, but these APIs can returnnull:src/Servy.Core/Helpers/ResourceHelper.csDirectory.CreateDirectory(targetPathDir!)ArgumentNullExceptioncrashsrc/Servy.Core/IO/RotatingStreamWriter.cs_file.Directory!.FullNamesrc/Servy.Core/IO/RotatingStreamWriter.csPath.GetDirectoryName(...)!src/Servy.Service/Helpers/ServiceHelper.csPath.Combine(dir!, ...)Path.GetDirectoryNamereturnsnullfor root paths.FileInfo.Directoryreturnsnullwhen constructed with a bare filename.Severity
Warning — NRE crashes in log rotation and service recovery code paths.
Suggested fix
Add explicit null checks before using these values, with appropriate fallback behavior or error messages.