-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
a:new-ruleProposal to add a new built-in ruleProposal to add a new built-in rulegood first issueA great starting point for new contributorsA great starting point for new contributors
Description
I'd like to suggest a new rule to detect reliance on the JVM default charset. This would need to cover multiple constructors/methods that have overloads with and without Charset
s.
I'd be happy to contribute a pull request but would like some guidance on how it should be implemented. Should it be a single XPath rule that covers all of the APIs, or a separate rule for each?
APIs that I know of so far:
java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
java.io.PrintStream#PrintStream(java.io.File)
java.io.PrintStream#PrintStream(java.io.OutputStream)
java.io.PrintStream#PrintStream(java.io.OutputStream, boolean)
java.io.PrintWriter#PrintWriter(java.io.File)
java.io.PrintWriter#PrintWriter(java.io.OutputStream)
java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
java.io.PrintWriter#PrintWriter(java.lang.String)
java.lang.String#getBytes()
java.lang.String#String(byte[], int, int, int)
java.lang.String#String(byte[], int)
java.util.Formatter#Formatter(java.lang.String)
java.util.Formatter#Formatter(java.io.File)
java.util.Formatter#Formatter(java.io.OutputStream)
java.util.Scanner#Scanner(java.io.InputStream)
java.util.Scanner#Scanner(java.io.File)
java.util.Scanner#Scanner(java.nio.file.Path)
java.util.Scanner#Scanner(java.nio.channels.ReadableByteChannel)
java.util.Scanner#Scanner(java.io.InputStream)
Affects PMD Version:
6.20.0
Rule:
New Rule
Description:
Be sure to specify a character set for APIs that use the JVMs default character set to ensure stable decoding between different JVMs, programs, and servers.
Code Sample demonstrating the issue:
new InputStreamReader(inputStream);
should be written as, for example:
new InputStreamReader(inputStream, StandardCharset.UTF_8);
rudikershaw and SaltyAimbOtter
Metadata
Metadata
Assignees
Labels
a:new-ruleProposal to add a new built-in ruleProposal to add a new built-in rulegood first issueA great starting point for new contributorsA great starting point for new contributors