users@jersey.java.net

[Jersey] Re: Non-determinism in selection of resource method on java 1.7

From: Gili T. <cowwoc_at_bbs.darktech.org>
Date: Thu, 24 Jan 2013 14:44:02 -0500

Hi,

It is true that JDK 1.7 changes the implementation of Class.getMethods()
but any application that assumes specific ordering is actually violating
the method specification. In other words, if you see Jersey's behavior
changing due to the changed behavior of Class.getMethods() it would be a
bug in Jersey, not the JDK.

Gili


On Thu, Jan 24, 2013 at 11:29 AM, <jannick_at_ovja.dk> wrote:

> Hi,
>
> Have run into an issue after upgrading to java 1.7 where the resource
> methods "preferred" by Jersey (1.4) has changed. From what we can tell
> this is consequence of the ordering of Class.getMethods() changing /
> becoming less stable in java 7.
>
> Issue description:
> - Receiving GET request with Accept: */*
> - Have a 'ProductResource' class (below) that produce a StatusResource
> from an exposed method
> - The resource class (at end of mail) have two @Produces methods, one
> for application/xml, and one for plain text
> - On java 1.6 Jersey would always choose the getStatus() method. On 1.7
> the getStatusAsText() method will be chosen on *some* machines.
>
> Was wondering if anyone else has run into this issue, know of a
> workaround, or know that it might have been fixed in a newer version of
> Jersey. The nice solution would be if would could specify a priority
> between candidate methods, but have not been able to find a way of
> doing so.
>
> @Path("/products/{id}")
> public class ProductResource{
>
> @Path("status")
> return new StatusResource(...);
> }
>
> }
>
> public class StatusResource {
>
> @GET
> @Produces(MediaType.APPLICATION_XML)
> public StatusSO getStatus() {
> return ...;
> }
>
>
> @GET
> @Produces(MediaType.TEXT_PLAIN)
> public String getStatusAsText() {
> return ...;
> }
>