jersey
  1. jersey
  2. JERSEY-1259

Array out of bounds error when you specify an empty list of @Produces annotation

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.12
    • Fix Version/s: 1.14
    • Component/s: core
    • Labels:
      None

      Description

      If you try to specify that a method doesn't produce anything:

      @PUT
      @Produces({})
      public Response putObject()
      {
      return Response.create(new URI(....)).build();
      }

      You end with an array out of bounds error HttpHeaderReader.readQualitySourceMediaType when building up the WADL.

      I have supplied a proposed patch and a unit test. The change means that in the above case an empty response element is created in the WADL as not representations are specified.

        Activity

        Hide
        gdavison added a comment -

        Workaround it to have the method return void, so the WADL is correct, and then throw an exception on the last line.

        throw new WebApplicationException(Response....);

        Show
        gdavison added a comment - Workaround it to have the method return void, so the WADL is correct, and then throw an exception on the last line. throw new WebApplicationException(Response....);
        Hide
        Michal Gajdos added a comment -

        Can you describe your use case for using @Produces with no value specified? Because I think this may be violating the spec:

        An implementation MUST NOT invoke a method whose effective value of @Produces does not match
        the request Accept header.

        Show
        Michal Gajdos added a comment - Can you describe your use case for using @Produces with no value specified? Because I think this may be violating the spec: An implementation MUST NOT invoke a method whose effective value of @Produces does not match the request Accept header.
        Hide
        gdavison added a comment -

        So you might have a method that just returns a status code of 202, for example when performing some kind of asynchronous action.:

        <method name="POST">
        <request>
        <representation xmlns:t="urn:example" mediaType="application/xml" element="t:object"/>
        <representation mediaType="application/xml"/>
        </request>
        <response status="202"/>
        </method>

        In this case there is not content body; but if you don't add a @Produces annotation that the response content type will default to / which is misleading in this case.

        Show
        gdavison added a comment - So you might have a method that just returns a status code of 202, for example when performing some kind of asynchronous action.: <method name="POST"> <request> <representation xmlns:t="urn:example" mediaType="application/xml" element="t:object"/> <representation mediaType="application/xml"/> </request> <response status="202"/> </method> In this case there is not content body; but if you don't add a @Produces annotation that the response content type will default to / which is misleading in this case.
        Hide
        Michal Gajdos added a comment -

        You can try to create a custom WadlGeneratorConfig with WadlGeneratorResourceDocSupport defined (see extended-wadl-webapp for an example). Then you can add a javadoc to your method like:

        /**
          * @response.representation.202.id
          */
        

        to generate a response element with empty representation subelement in the WADL:

        <response status="202">
           <representation/>
        </response>
        
        Show
        Michal Gajdos added a comment - You can try to create a custom WadlGeneratorConfig with WadlGeneratorResourceDocSupport defined (see extended-wadl-webapp for an example). Then you can add a javadoc to your method like: /** * @response.representation.202.id */ to generate a response element with empty representation subelement in the WADL: <response status= "202" > <representation/> </response>
        Hide
        Michal Gajdos added a comment -

        There is an inconsistency with the spec (section 3.8) - when a resource method is annotated with @Produces({}) then the producible media type of a response is not determined correctly ("/") and the HTTP 406 is returned which is wrong.

        Show
        Michal Gajdos added a comment - There is an inconsistency with the spec (section 3.8) - when a resource method is annotated with @Produces({}) then the producible media type of a response is not determined correctly (" / ") and the HTTP 406 is returned which is wrong.
        Hide
        Michal Gajdos added a comment -

        Fixed for 1.14.

        Show
        Michal Gajdos added a comment - Fixed for 1.14.

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            gdavison
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 2 hours
              2h