Implicit use of the platform default charset, which can result in e.g. non-ASCII characters being silently replaced with '?' in many environments


The problem

A Charset is a mapping between sequences of 16-bit Unicode code units and sequences of bytes. Charsets are used when encoding characters into bytes and decoding bytes into characters.

Using APIs that rely on the default Charset under the hood is dangerous. The default charset can vary from machine to machine or JVM to JVM. This can lead to unstable character encoding/decoding between runs of your program!

If you need stable encoding/decoding, you must specify an explicit charset. The StandardCharsets class provides these constants for you.

When in doubt, use UTF-8.


Suppress false positives by adding the suppression annotation @SuppressWarnings("DefaultCharset") to the enclosing element.