Standard Analyses

SemmleCode Professional comes with a wide range of pre-packaged analyses, from architectural properties and metrics, to statement-level checks for likely bugs and violations of best practice.


Bad Internationalization

This query finds uses of String.toUpperCase() and String.toLowerCase() that do not use explicit locale parameters. The result of the conversion is then dependent on the standard locale, making the program non-portable.

For example, if the standard locale is English, the statement

    System.out.println("I".toLowerCase());

prints i; with a Turkish locale, it prints ı, i.e. a ``dotless i''.

How to Interpret the Query Results

The query flags all calls to these methods and provides a list of all detected occurrences in the results view.

How to Address the Query Results

Use the corresponding methods with explicit locale parameters. For example

    System.out.println("I".toLowerCase(java.util.Locale.ENGLISH));

prints i, regardless of the default locale.

Source Code
import default

from MethodAccess ma, Method changecase
where (   changecase.hasName("toUpperCase")
       or changecase.hasName("toLowerCase")) and
      changecase.hasNoParameters() and
      changecase.getDeclaringType() instanceof TypeString and
      ma.getMethod() = changecase
select ma, changecase.getName() + " without locale parameter"
References

JDK API documentation for String.toUpperCase()