Annotation processor does not flag constraints on methods that override or implement superclass or interface methods

Description

Per the spec, methods specified in a superclass or interface should only be annotated where they are originally defined (the contract). If an implementation or extending class contains constraint annotations on these methods, it should result in an exception (because it alters the contract understood by the consumer of the interface).

This is all well and good, except that the annotation processor does not catch these types of programming errors, so if you mistakenly annotate an overridden or implemented method you won't notice until runtime. The annotation processor should flag constraints on methods that override or implement superclass or interface methods so that this problem can be caught during compilation.

Environment

None

Activity

Nick WilliamsJune 9, 2013 at 9:07 PM

Gunnar, unfortunately right now I'm writing a book (Java8+EE7+Spring4+BV1.1+JPA2.1+SpringSecurity) and that is keeping me very busy. Perhaps if, in the coming months it has not been implemented yet, I'd be able to help out. I'm being kept busy filing and fixing bugs in Spring 4.0 so that I can keep my book moving along.

Gunnar MorlingJune 9, 2013 at 9:04 PM
Edited

Nick, thanks for your report. Unfortunately the annotation processor does not yet implement the rules around method validation.

Would you be interested in contributing these checks? This would basically require a new implementation of ConstraintCheck and its registration in ConstraintCheckFactory. Btw. this particular check is actually easier to implement in the annotation processor than in the runtime by using the overrides() method from the Elements helper.

Duplicate

Details

Assignee

Reporter

Labels

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Gunnar Morling
Nick Williams

Original estimate

Time tracking

No time logged8h remaining

Components

Affects versions

Priority

Created June 9, 2013 at 7:48 PM
Updated December 3, 2024 at 9:28 AM
Resolved December 8, 2016 at 11:14 AM