Back to all reviewers

prefer system properties directly

apache/spark
Based on 2 comments
Java

When detecting operating system or environment characteristics, prefer direct access to system properties over external library dependencies for basic checks. Use `System.getProperty("os.name")` with `regionMatches()` for case-insensitive OS detection instead of relying on third-party utilities like Apache Commons Lang3's SystemUtils.

Configurations Java

Reviewer Prompt

When detecting operating system or environment characteristics, prefer direct access to system properties over external library dependencies for basic checks. Use System.getProperty("os.name") with regionMatches() for case-insensitive OS detection instead of relying on third-party utilities like Apache Commons Lang3’s SystemUtils.

This approach reduces external dependencies while maintaining equivalent functionality. The regionMatches() method provides robust, case-insensitive string matching that handles OS name variations effectively.

Example implementation:

// Instead of: SystemUtils.IS_OS_WINDOWS
boolean isWindows = System.getProperty("os.name").regionMatches(true, 0, "Windows", 0, 7);

// Instead of: SystemUtils.IS_OS_UNIX  
String osName = System.getProperty("os.name");
String[] unixPrefixes = {"AIX", "HP-UX", "Linux", "Mac OS X", "Solaris", "FreeBSD"};
boolean isUnix = Arrays.stream(unixPrefixes)
    .anyMatch(prefix -> osName.regionMatches(true, 0, prefix, 0, prefix.length()));

This pattern is particularly valuable when the external library is used minimally and the custom implementation can be easily maintained and tested.

2
Comments Analyzed
Java
Primary Language
Configurations
Category

Source Discussions