AnnotatedMember.equals()
does not work reliably
#3187
Milestone
AnnotatedMember.equals()
does not work reliably
#3187
Hi,
I noticed some strange behavior of the current
AnnotatedMember.equals()
implementations. Following test case forAnnotatedConstructor.equals()
currently fails:Based on the first two successful
assertEquals(...)
statements, I would have expected that the thirdassertEquals(...)
should be also successful. However, it currently fails.The reason for this behavior is that
AnnotatedConstructor.equals()
is currently using==
for comparing the two constructors:However, the implementation of the reflection API in
java.lang.Class
is always copying / cloning theField
,Method
andConstructor
instances prior to returning them to the caller (e.g. seeClass.copyConstructors()
). Thus, each call ofClass.getConstructors()
will always return new instances.If you agree that the above test case should be successful (i.e. also
assertEquals(instance1.getDefaultConstructor(), instance2.getDefaultConstructor())
should be successful), I would prepare a corresponding pull request that slightly modifies the current implementation of theequals()
method for all subclasses ofAnnotatedMember
that are affected by this problem (i.e. at leastAnnotatedField
,AnnotatedConstructor
andAnnotatedMethod
).The text was updated successfully, but these errors were encountered: