Skip to content

New check request: handle @Override on record component declarations somehow #5174

Description

@kevinb9n

Because @Override is a @Target(METHOD) annotation, it's automatically permitted on record component declarations. It would normally cause the annotation to be copied to the generated accessor method, but in this case it's a SOURCE-retention annotation so there's nothing to do.

But it misses out on the normal javac enforcement of @Override, and the annotation ends up being meaningless.

It could have a reasonable meaning: it could ensure that the generated accessor method is overriding something.

From what I understand so far it would be reasonable for JLS to have required this enforcement (personal opinion only), but it's not something we'd be likely to fix any time soon. So, Error Prone might want to provide this enforcement, maybe?

And if so, then I guess the @Override suggester might also want to address this case. But it would be bad to suggest adding @Override to a record component if it wasn't being enforced. (I assume the suggester doesn't already do that?)

As a side note, a hand-written accessor method in a record class can also always use @Override regardless of supertype methods (JLS 9.6.4.4 explains). That should be unrelated to this though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions