Skip to content
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

Clarify AnnotatedMember#getDeclaringType #535

Open
JHahnHRO opened this issue Sep 27, 2021 · 0 comments
Open

Clarify AnnotatedMember#getDeclaringType #535

JHahnHRO opened this issue Sep 27, 2021 · 0 comments

Comments

@JHahnHRO
Copy link

JHahnHRO commented Sep 27, 2021

When AnnotatedMember#getDeclaringType() is called on a member of some AnnotatedType<T>, a AnnotatedType<? super T> is returned, because both getMethods and getFields are defined to return Set<AnnotatedX<? super T>>. I expect the underlying class to be the declaring class of the member in the sense of java.lang.reflect.Member#getDeclaringClass(), see https://issues.redhat.com/browse/WELD-2681.

EDIT: @mkouba commented on that WELD issue and corrected my understanding of what getDeclaringType() is supposed to do. Instead of a question, let me re-phrase it as a request. (My second questions remain)

Request:

Have the spec explain in more detail what AnnotatedType exactly gets returned by AnnotatedMember#getDeclaringType(), how that differs from Method.getDeclaringClass() and what annotations are expected to be present on this type (and its members, see below). Explain that the returned Set<AnnotatedMethod<? super T>> of AnnotatedType<T>#getMethods (and similar for getFields()) is always an instance of Set<AnnotatedMethod<T>> in practice, even if the interface suggests otherwise. Better yet, change the interface itself to correct the return type. (But assume that would be a breaking change.)

Question 2: Round trips

And come to think of it: Is it expected that "round-trips" work, i.e. should
myAnnotatedMethod.getDeclaringType().filterMethods(m -> m.equals(myAnnotatedMethod)).findAny()
be guaranteed to be a non-empty Optional? Should maybe even
myAnnotatedMethod.getDeclaringType().filterMethods(m -> m == myAnnotatedMethod).findAny()
be guaranteed to be non-empty?
If yes, then the AnnotatedType returned by getDeclaringType() must be a different instance every time a configurator is used to modify an AnnotatedMember, right? If no, what differences between myAnnotatedMethod and the corresponding AnnotatedMethod contained in myAnnotatedMethod.getDeclaringType().getMethods() are allowed and how does the container react if there are differences?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant