Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix FindBugs' warning "Use of non-localized String.toUpperCase() or String.toLowerCase()"?

Tags:

java

findbugs

I have following piece of code:

/**
 * Performs the filename extension check (command-line argument validity).
 * @param valid True, if the check should be performed.
 * @param filename File name to test.
 * @return False, if the test was done and the filename does not end with
 *  ".xml". Value of valid otherwise.
 */
private boolean checkFileNameExtension(final boolean valid,
    final String filename) {
    boolean result = valid;
    if (valid
        && !filename.toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
        this.logger.error("File doesn't have XML extension.");
        result = false;
    }
    return result;
}

FindBugs complains about the toLowerCase call:

[WARNING] FindBugs: L I Dm: Use of non-localized String.toUpperCase() or 
String.toLowerCase() in [...]checkFileNameExtension(boolean, String)

How can I correctly fix that warning (the proper way), if I can be sure that all file names will always have names with Latin letters only?

like image 440
Dmitrii Pisarenko Avatar asked Jul 05 '15 20:07

Dmitrii Pisarenko


1 Answers

Adding Locale.ENGLISH (or Locale.ROOT) is the proper way to fix the error, so if FindBugs is still reporting that error after you add that, then you might have found a bug in FindBugs itself.

like image 190
Brett Kail Avatar answered Nov 29 '22 11:11

Brett Kail