Description
string.IsNullOrWhiteSpace() and string.IsNullOrEmpty() are used interchangeably throughout the codebase for the same semantic purpose (checking if a value is set):
IsNullOrWhiteSpace (~50+ instances):
Servy.CLI/Validators/ServiceInstallValidator.cs — 30+ validation checks
Servy.Core/Native/NativeMethods.cs:389,415 — username validation
Servy.CLI/Commands/ExportServiceCommand.cs:38,42,45
IsNullOrEmpty (~45 instances):
Servy.CLI/Commands/BaseCommand.cs:30,41,69,80 — suggestion checks
Servy.Manager/Services/ServiceCommands.cs:147,149,204,206
Servy.Service/Service.cs:662,694,733
Servy.Core/Logging/Logger.cs:72,281
Sometimes both appear in the same file: ServiceDependenciesValidator.cs uses IsNullOrWhiteSpace on line 22 and IsNullOrEmpty on line 36.
These have different semantics: IsNullOrWhiteSpace also rejects " " (whitespace-only). Using them interchangeably means some paths accept whitespace-only strings while equivalent paths don't.
Severity
Info — inconsistent validation strictness across equivalent checks.
Suggested fix
Standardize on IsNullOrWhiteSpace for user-facing validation (the stricter check), and IsNullOrEmpty only where whitespace-only strings are intentionally valid.
Description
string.IsNullOrWhiteSpace()andstring.IsNullOrEmpty()are used interchangeably throughout the codebase for the same semantic purpose (checking if a value is set):IsNullOrWhiteSpace (~50+ instances):
Servy.CLI/Validators/ServiceInstallValidator.cs— 30+ validation checksServy.Core/Native/NativeMethods.cs:389,415— username validationServy.CLI/Commands/ExportServiceCommand.cs:38,42,45IsNullOrEmpty (~45 instances):
Servy.CLI/Commands/BaseCommand.cs:30,41,69,80— suggestion checksServy.Manager/Services/ServiceCommands.cs:147,149,204,206Servy.Service/Service.cs:662,694,733Servy.Core/Logging/Logger.cs:72,281Sometimes both appear in the same file:
ServiceDependenciesValidator.csusesIsNullOrWhiteSpaceon line 22 andIsNullOrEmptyon line 36.These have different semantics:
IsNullOrWhiteSpacealso rejects" "(whitespace-only). Using them interchangeably means some paths accept whitespace-only strings while equivalent paths don't.Severity
Info — inconsistent validation strictness across equivalent checks.
Suggested fix
Standardize on
IsNullOrWhiteSpacefor user-facing validation (the stricter check), andIsNullOrEmptyonly where whitespace-only strings are intentionally valid.