Skip to content

private enums being treated as public in JavadocVariableCheck #16786

@JackPGreen

Description

@JackPGreen

Take a simple class with a private enum:

public class MyClass {
    private enum PrivateEnum {
        CONSTANT
    }
}

When run with a simple checkstyle.xml:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="JavadocVariable">
            <property name="accessModifiers" value="public"/>
        </module>
    </module>
</module>

[ERROR] MyClass.java:3:9: Missing a Javadoc comment. [JavadocVariable] is thrown.

While investigating, the change in #16049 identifies any enum constant as being implicitly public (correct), but doesn't check if the enum itself is accessible (which it isn't, because private).

Specifically, while upgrading checkstyle from 10.21.4 to 10.22.0 many such pre-existing private enums were now being flagged as violations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions