Skip to content

ArrayTypeStyle false positives in nested generics #10215

@jdussouillez

Description

@jdussouillez

Rule : ArrayTypeStyle

The ArrayTypeStyle seems to fail when checking the declaration inside nested generics. It works as expected with the 8.43 but fails with the 8.44.

// Test.java
public class Test {

    protected Pair<Integer, Object>[] values1; // OK
    protected Pair<Integer, Pair<String, Object>[]>[] values2; // OK
    protected Pair<Integer, Pair<String, Pair<String, Object>>[]>[] values3a; // KO!
    protected Pair<
        Integer,
        Pair<
            String,
            Pair<String, Object>
        >[]
    >[] values3b; // OK, but in fact it's the same as "values3a" with another format

    protected static class Pair<L, R> {
        protected L key;
        protected R value;
    }
}
<!-- checkstyle.xml -->
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
    <property name="charset" value="UTF-8"/>
    <property name="severity" value="error"/>

    <module name="SuppressWithPlainTextCommentFilter"/>
    <property name="fileExtensions" value="java, properties, xml"/>
    <module name="TreeWalker">
        <module name="ArrayTypeStyle"/>
    </module>
</module>
$ java -jar checkstyle-8.44-all.jar -c checkstyle.xml Test.java
Starting audit...
[ERROR] /home/junior/Downloads/Test.java:5:66: Array brackets at illegal position. [ArrayTypeStyle]
Audit done.
Checkstyle ends with 1 errors

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions