Skip to content

Detect final methods in Enumeration for RedundantModifier #2068

@rnveach

Description

@rnveach

Code:

package test;

public enum TestEnum1 {
    ;

    public static final TestEnum1 get() { // line 6
        return null;
    }

    public final TestEnum1 test() { // line 10
        return null;
    }
}

Config:

<module name="Checker">
    <property name="charset" value="ASCII" />
    <property name="severity" value="error" />
    <property name="fileExtensions" value="java" />

    <module name="TreeWalker">
        <module name="RedundantModifier">
        </module>
    </module>
</module>

Output:

Starting audit...
Audit done.

I expected line 6's and 10's "final" to be marked as a redundant modifier but it is not. Final methods mean it cannot be overridden when the class is inherited but enumerations cannot be inherited anyways as they are not a class. Check style should treat the enumeration as if it were a final class, which it would then mark as redundant.
I am using checkstyle 6.10.1 .

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions