New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect final methods in Enumeration for RedundantModifier #2068

Closed
rnveach opened this Issue Sep 1, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@rnveach
Member

rnveach commented Sep 1, 2015

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 .

@tgyurci

This comment has been minimized.

Show comment
Hide comment
@tgyurci

tgyurci Sep 24, 2015

Enum members can be subclasses of the enum type and some member can override the base enum class's method:

public enum TestEnum {
    E1,

    E2 {
        @Override
        public void v() {
        }
    };

    public void v() {
    }
}

That's why it makes sense that enum member functions are final or not. In addition the RedundantModifierCheck marks final redunant in enum member declarations:

public enum TestEnum {
    E1,

    E2 {
        @Override
        public final void v() {
        }
    };

    public void v() {
    }
}

tgyurci commented Sep 24, 2015

Enum members can be subclasses of the enum type and some member can override the base enum class's method:

public enum TestEnum {
    E1,

    E2 {
        @Override
        public void v() {
        }
    };

    public void v() {
    }
}

That's why it makes sense that enum member functions are final or not. In addition the RedundantModifierCheck marks final redunant in enum member declarations:

public enum TestEnum {
    E1,

    E2 {
        @Override
        public final void v() {
        }
    };

    public void v() {
    }
}

@romani romani added the approved label Sep 24, 2015

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Sep 24, 2015

Member

We need to extend input code base with example from tgyurci . It is not obvious.

Member

romani commented Sep 24, 2015

We need to extend input code base with example from tgyurci . It is not obvious.

@romani romani assigned liscju and rnveach and unassigned liscju Sep 25, 2015

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Nov 24, 2016

Member

RedundantModifierCheck marks final redunant in enum member declarations

I wasn't getting any violations on current version or previous versions, so I will create a new issue for this.

Member

rnveach commented Nov 24, 2016

RedundantModifierCheck marks final redunant in enum member declarations

I wasn't getting any violations on current version or previous versions, so I will create a new issue for this.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Nov 26, 2016

Member

Fix is merged

Member

romani commented Nov 26, 2016

Fix is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment