[java] New rule: trim() -> strip()

Replace usage of non unicode aware trim() with unicode aware strip() for a String.

The old String.trim() method is not unicode aware and only removes chacters <= U+0020. In contrast String.strip(), stripLeading() and stripTrailing() recognize all unicode whitespaces.

Non compliant:
String s = " hello world ".trim();

Compliant:
String s = " hello world ".strip();

Type : Security Hotspot… just kidding. Code Smell!
Tags: Java

1 Like