Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-952

@Context injection doesn't work in super class


    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.6.Final
    • 3.0.1.Final
    • jaxrs
    • None

      In RESTEasy 2.3.2 the @Context annotation can be used to inject the context variables declared in the super class of a resource implementation. However, in RESTEasy 3.0.1 this functionality no longer works.

      In the following example the super class declares a context variable:

      public class BaseService {
          protected UriInfo uriInfo;

      In the subclass the context variable is used in a method:

      public class SomeService extends BaseService implements SomeResource {
          public void execute() {
              UriBuilder builder = uriInfo.getRequestUriBuilder();

      With RESTEasy 2.3.2 the method works just fine, but with RESTEasy 3.0.1 it now throws a null pointer exception since the context variable is never initialized.

      It looks like RESTEasy 3.0.1 will only iterate through the fields
      declared explicitly in the resource implementation, so the context variable in the super class is not registered for injection:

      public class ResourceBuilder {
          protected static void processDeclaredFields(...) {
              for (Field field : root.getDeclaredFields()) {
                  ... register field for injection ...

      There is another ticket describing a similar issue:
      but that ticket was filed for version 1.1 GA and it's still open.

      The current issue seems to be different because it used to work in version 2.3.2.

            rsigal@redhat.com Ronald Sigal
            edewata Endi Dewata
            1 Vote for this issue
            4 Start watching this issue