users@jersey.java.net

Annotation inheritance & covariant return types?

From: Tim Pesce <tpesce_at_well.com>
Date: Wed, 1 Oct 2008 09:55:01 -0600

I've run into a situation that looks like a potential defect. I've
also searched the mailing lists and issue tracker, but haven't been
able to find anything related. I'm happy to create a new issue, but
I'd like to make sure this isn't a case of user error first.

I have two simple classes that use annotation inheritance on a method
with covariant return types:

public abstract class RandomNumber {
     protected static Random r = new Random(System.currentTimeMillis());

     @GET
     @Produces("text/plain")
     public abstract Number get();
}

@Path("integer")
public class RandomInteger extends RandomNumber {
     public Integer get() {
         return r.nextInt();
     }
}

At init time Jersey produces this:

Oct 1, 2008 9:10:59 AM
com.sun.jersey.impl.application.WebApplicationImpl newResourceClass
SEVERE: A resource, class test.resources.RandomInteger, has ambiguous
resource method for HTTP method GET and output mime-type: text/plain.
The problematic mime-type sets (as defined by @Produces annotation at
Java methods get and get) are [text/plain] and [text/plain]

I think the validator may not be accounting for bridge methods:

Method[] methods = RandomInteger.class.getMethods();
for (Method m : methods) {
     System.out.printf("%s (bridge=%b)\n", m, m.isBridge());
}

public java.lang.Integer test.resources.RandomInteger.get()
(bridge=false)
public java.lang.Number test.resources.RandomInteger.get() (bridge=true)
[...]

I'm using 0.11 and java version "1.6.0_07" (Mac)

Thanks,

Tim