-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ClientProxy getClass().getAnnotations() does not return actual annotations on the class #30327
Comments
It's not a bug per se but a known limitation. If you really need to inspect annotations via reflection: if |
@mkouba I understand that, but maybe the proxy/subclass can be enhanced to delegate the |
I think that we would have to copy all annotations instead, i.e. delegation is not possible. And that's something we would like to avoid. |
Note that you can fiddle with annotations programmatically (which isn't uncommon in case of CDI) meaning that the view you get from reflection isn't always complete. |
@manovotn unfortunately this may not be an option, as the code is not always under control.
I could override this method in my errorhandler (which is not very pretty), but I reckon there may also be other third-party libraries that rely on annotations
This is something that I expect the framework to take care of for me, hence the issue. |
Technically, you can unwrap the proxy to see the actual bean (and use reflection on it), but that's impl dependent - for instance different between Quarkus and Weld.
What I am trying to say here is that the reflection is not good enough as a tool to actually see all annotations no matter what the framework does for it - at least in terms of CDI beans and CDI-related annotations. |
Looking at CDI specification, it states the following:
Therefore, invoking I'll close this issue as it's not a bug and there are workarounds to unwrap the proxy and get to actual bean class instance. |
Describe the bug
I'm not sure if this is indeed a bug, or a limitition, but it is something that I came across right now and wonder if there is a way to make this work with beans that are proxied/subclassed (like
@ApplicationScoped
).Due to the nature of subclassing managed beans, getAnnotations() does not yield all present annotations (unless they are marked as
@Inherited
)because of that, certain code that depend on runtime annotations like
(taken from
org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper
) does not work on quarkus beans unless they are marked as@Singleton
.Expected behavior
getAnnotations() should work on proxies as well.
If this is technically not possible, the documentation should be updated to include this (and other known) limitations of using
@ApplicationScoped
over@Singleton
Actual behavior
getAnnotations() only returns
@Inherited
annotationsHow to Reproduce?
Sample project: https://github.com/ssaip/quarkus-getannotations/blob/main/src/test/java/com/example/AnnotatedClassTest.java
Output of
uname -a
orver
No response
Output of
java -version
Java version: 11.0.17, vendor: Azul Systems, Inc.
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.15.3.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)apache-maven-3.8.6
Additional information
No response
The text was updated successfully, but these errors were encountered: