Using classes and methods that rely on the default system encoding can result in code that works fine in its "home" environment. But that code may break for customers who use different encodings in ways that are extremely difficult to diagnose and nearly, if not completely, impossible to reproduce when it’s time to fix them.
This rule detects uses of the following classes and methods:
FileReader
FileWriter
byte[]
argument but no Charset
argument
String(byte[] bytes)
String(byte[] bytes, int offset, int length)
String.getBytes()
String.getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
InputStreamReader(InputStream in)
OutputStreamWriter(OutputStream out)
ByteArrayOutputStream.toString()
Formatter
constructors
Formatter(String fileName)
Formatter(File file)
Formatter(OutputStream os)
Scanner
constructors
Scanner(File source)
Scanner(Path source)
Scanner(InputStream source)
PrintStream
constructors
PrintStream(File file)
PrintStream(OutputStream out)
PrintStream(OutputStream out, boolean autoFlush)
PrintStream(String fileName)
PrintWriter
constructors
PrintWriter(File file)
PrintWriter(OutputStream out)
PrintWriter(OutputStream out, boolean autoFlush)
PrintWriter(String fileName)
IOUtils.copy(InputStream, Writer)
IOUtils.copy(Reader, OutputStream)
IOUtils.readLines(InputStream)
IOUtils.toByteArray(Reader)
IOUtils.toByteArray(String)
IOUtils.toCharArray(InputStream)
IOUtils.toInputStream(TypeCriteria.subtypeOf(CharSequence))
IOUtils.toString(byte[])
IOUtils.toString(URI)
IOUtils.toString(URL)
IOUtils.write(char[], OutputStream)
IOUtils.write(CharSequence, OutputStream)
IOUtils.writeLines(Collection, String, OutputStream)
FileUtils.readFileToString(File)
FileUtils.readLines(File)
FileUtils.write(File, CharSequence)
FileUtils.write(File, CharSequence, boolean)
FileUtils.writeStringToFile(File, String)