Format strings should use `%n` instead of `\\n`JAVA-W0379
This format string includes a newline character (\\n
). This may cause issues on platforms like Windows that do not use Unix line separators.
In format strings, it is generally preferable to use %n
, which will produce the platform-specific line separator.
Bad practice
String.format("%s\\n%d", "number", 3);
Recommended
String.format("%s%n%d", "number", 3);
References
- SpotBugs - VA_FORMAT_STRING_USES_NEWLINE