Affects PMD Version: 6.14.0
Rule: SimplifyStartsWith
Description: pmd reports that expression can be simplified, but if string is empty, "simplified" code produces StringIndexOutOfBoundsException
Code Sample demonstrating the issue:
public class Example {
public static void main(String[] args) {
System.out.println(checkStringStartsFrom(""));
System.out.println(checkStringCharAt(""));
}
private static boolean checkStringStartsFrom(String string) {
return string.startsWith("*");
}
private static boolean checkStringCharAt(String string) {
return string.charAt(0) == '*';
}
}
Running PMD through: Maven
Affects PMD Version: 6.14.0
Rule: SimplifyStartsWith
Description: pmd reports that expression can be simplified, but if string is empty, "simplified" code produces StringIndexOutOfBoundsException
Code Sample demonstrating the issue:
Running PMD through: Maven