Skip to content

[java] Merge rules about protected in final class (AvoidProtectedFieldInFinalClass, AvoidProtectedMethodInFinalClassNotExtending) #2974

Closed

Description

@oowekyala

I think we should merge AvoidProtectedFieldInFinalClass and AvoidProtectedMethodInFinalClassNotExtending. Just like for #2892, it's useless to have a distinction when the fix is the same. The names are also long and clumsy, and give too much detail about the implementation, which doesn't allow us to extend the behavior of the rules.

Proposed rule name: "ProtectedMemberInFinalClass" in design.xml and not codestyle.

Other improvements we can make to this new rule:

  • protected nested types
  • protected members in an anonymous class, enum, or record
  • only ignore methods that override an inherited method (so stop checking blindly for an ExtendsList)

For example

final class MyList extends AbstractList<String> {

    // a false negative of the current rule
    protected void idontOverrideAnything() { }

}

Activity

  1. added
    an:enhancement
    a:new-rule
    on Dec 14, 2020
  2. added this to the 7.0.0 milestone on Dec 14, 2020
  3. modified the milestones: 7.0.0, 7.x on Jan 23, 2023
  4. modified the milestones: 7.x, 7.27.0 on Aug 19, 2026
  5. added
    is:deprecation
    on Aug 20, 2026
  6. changed the title [-][java] Merge rules about protected in final class[/-] [+][java] Merge rules about protected in final class (AvoidProtectedFieldInFinalClass, AvoidProtectedMethodInFinalClassNotExtending)[/+] on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-rulean:enhancementis:deprecation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions