users@jax-rs-spec.java.net

[jax-rs-spec users] Exception mapper ambiguity

From: Christian Kaltepoth <christian_at_kaltepoth.de>
Date: Mon, 18 Jul 2016 09:06:21 +0200

Hey all,

I just stumbled upon a minor inaccuracy in the specification. The matching
algorithm of an exception to an exception mapper is defined like this:

When choosing an exception mapping provider to map an exception, an
> implementation MUST use the provider whose generic type is the nearest
> superclass of the exception.


That's all. So the spec currently does not define which mapper is selected
if there are multiple ones for the same exception type. This is problematic
if there are multiple ones provided by the JAX-RS implementation, 3rd party
libraries or by the application itself.

This could be fixed if the JAX-RS specifies that in these cases the
@Priority annotation can be used to order the mappers. I think this pattern
is widely adopted in Java EE. We also use @Priority for ordering SPIs in
MVC 1.0.

Thoughts?

Christian


-- 
Christian Kaltepoth
Blog: http://blog.kaltepoth.de/
Twitter: http://twitter.com/chkal
GitHub: https://github.com/chkal