Skip to content

Mixed string empty checks: IsNullOrWhiteSpace vs IsNullOrEmpty used interchangeably #397

@Christophe-Rogiers

Description

@Christophe-Rogiers

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.

Metadata

Metadata

Assignees

Labels

refactorChanges that improve structure, readability, or maintainability without altering external behavior

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions