A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/1868 below:

[java] false-positive for SimplifyStartsWith if string is empty · Issue #1868 · pmd/pmd · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4