Back to all reviewers

Use environment-independent defaults

spring-projects/spring-framework
Based on 4 comments
Java

When designing configuration options, avoid relying on environment-specific defaults such as system character encodings, file paths, or platform-specific features. Instead, specify explicit defaults that work consistently across all supported environments. This prevents subtle bugs that manifest only in specific environments.

Configurations Java

Reviewer Prompt

When designing configuration options, avoid relying on environment-specific defaults such as system character encodings, file paths, or platform-specific features. Instead, specify explicit defaults that work consistently across all supported environments. This prevents subtle bugs that manifest only in specific environments.

For example, instead of using default charset for file operations:

// Problematic: relies on environment-specific default charset
new String(Files.readAllBytes(path), Charset.defaultCharset());

// Better: explicitly specifies charset (usually UTF-8)
new String(Files.readAllBytes(path), StandardCharsets.UTF_8);

Be especially careful when changing defaults, as this can break existing configurations. Consider IDE compatibility issues when using specific language features or imports, as seen in discussion #3 where a private constant was needed instead of a direct import to avoid Eclipse compilation errors. When updating defaults is necessary, reserve such changes for major version releases to prevent breaking existing tests and deployments.

4
Comments Analyzed
Java
Primary Language
Configurations
Category

Source Discussions