-
Notifications
You must be signed in to change notification settings - Fork 357
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
@Priority is not always picked up correctly for JAX-RS providers #4099
Comments
Please see #4100 for a possible fix. Although I'm not completely sure if it is the best place for a fix. |
I created #4101 which contains an integration test which reproduces this issue. I hope this helps. |
Merged
This was referenced Jun 26, 2021
This was referenced Aug 5, 2021
This was referenced Sep 5, 2021
This was referenced Oct 4, 2021
This was referenced Oct 18, 2021
This was referenced Oct 21, 2021
Merged
Merged
This was referenced Oct 21, 2021
Closed
Closed
1 task
This was referenced Mar 7, 2022
This was referenced Mar 15, 2022
This was referenced Apr 17, 2022
This was referenced May 3, 2022
1 task
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are still some cases where ordering of JAX-RS providers via
@Priority
doesn't work correctly. In my case there are twoExceptionMapper
instances for the same exception type but with different priorities. Jersey fails to pick up the@Priority
, which results in a default priority ofPriorities.USER
for both mappers and therefore in random ordering at runtime.IMO the problem actually occurs for all JAX-RS provider types. It occurs with Jersey 2.28. See the following analysis for details:
Custom providers are looked up in the
Providers
class like this:jersey/core-common/src/main/java/org/glassfish/jersey/internal/inject/Providers.java
Lines 287 to 290 in 895c293
The
getServiceHolders
method gets aComparator
which usesProviders.getPriority()
to order the providers according to the@Priority
annotation.jersey/core-common/src/main/java/org/glassfish/jersey/internal/inject/Providers.java
Lines 363 to 371 in 895c293
Everything is fine so far.
The problem is that
Providers.getPriority()
isn't always called with the actual provider implementation class but sometimes gets an instance oforg.glassfish.jersey.inject.hk2.InstanceSupplierFactoryBridge
. This means that Jersey sometimes looks for the@Priority
on the wrong class and is ignoring the@Priority
on the actual implementation class.The
Providers
class seems to useServiceHolder.getImplementationClass()
to get the type of the provider class, which doesn't work correctly in all cases.jersey/core-common/src/main/java/org/glassfish/jersey/internal/inject/Providers.java
Lines 313 to 315 in 895c293
My current guess is that it should useServiceHolder.getImplementation**Type**()
instead. But I'll need to verify that. I'll try to create a failing integration tests for this issue.-The text was updated successfully, but these errors were encountered: