Skip to content

[java] UseStandardCharsets: False negative with Java 22+ and UTF-32 charsets #6719

@zbynek

Description

@zbynek

Affects PMD Version:
7.24.0

Rule:

https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#usestandardcharsets

Description:

Java 22 added 32 bit encodings to StandardCharsets, these are not supported by the UseStandardCharsetsRule rule. The fix for this should depend on javaLevel.

Code Sample demonstrating the issue:

void main() {
byte[] bytes = "foo".getBytes("UTF-32");
}

Expected outcome:

PMD should report a violation at line 2, but doesn't. This is a false-negative.

Running PMD through: CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions