jersey
  1. jersey
  2. JERSEY-2387

Link.Builder#{build(), buildRelativized()} does not throw IAE when there are any URI template parameters without a supplied value

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.1
    • Fix Version/s: 2.7
    • Component/s: core
    • Labels:
      None

      Description

      javadoc of Link.Builder#build/buildRelativized says:

      Throws:
      java.lang.IllegalArgumentException - if there are any URI template parameters without a supplied value

      The following code:

      Builder linkBuilder = Link.fromUri("scheme://authority/{x1}/{*x2}/{*x3}");
      linkBuilder.build("p");
      

      Throws the exception as expected, where as

      Builder linkBuilder = Link.fromUri("scheme://authority/{x1}/{*x2}/{*x3}");
      linkBuilder.build();
      

      Does not throw.
      It looks like JerseyUriBuilder#_build goes through:

              if (values == null || values.length == 0) {
                  return createURI(create());
              }
      

      with

          private String create() {
              return UriComponent.encodeTemplateNames(toTemplate());
          }
      

      and encodeTemplateNames replaces "{" with "%7B". When values != null, the code does not go through encodeTemplateNames

        Activity

        Hide
        jan.supol added a comment - - edited

        Now thinking about it, template

        /{x1}/{x2*}/{x3*}
        

        would have segments x2 and x3 optional. Is it correct that linkBuilder.build("p"); throws IAE?

        Show
        jan.supol added a comment - - edited Now thinking about it, template /{x1}/{x2*}/{x3*} would have segments x2 and x3 optional. Is it correct that linkBuilder.build("p"); throws IAE?
        Hide
        Marek Potociar added a comment -

        I do not understand the comment about optional segments. What makes the segments optional? The asterisk ('*') ?
        Please also note that template parameter names such as {*x2} used in the issue description are illegal.

        That said, you do have a point that (according to JAX-RS apidocs) UriBuilder, Link.Builder and WebTarget should all fail when attempting to create a URI instance from a URI template that contains unresolved template parameters. I am surprised we only now discovered the issue (and that we did not discover it as part of UriBuilder TCK tests. I will look into fixing the Jersey implementation to comply with the specification javadocs.

        Show
        Marek Potociar added a comment - I do not understand the comment about optional segments. What makes the segments optional? The asterisk ( '*' ) ? Please also note that template parameter names such as { *x2 } used in the issue description are illegal. That said, you do have a point that (according to JAX-RS apidocs) UriBuilder , Link.Builder and WebTarget should all fail when attempting to create a URI instance from a URI template that contains unresolved template parameters. I am surprised we only now discovered the issue (and that we did not discover it as part of UriBuilder TCK tests. I will look into fixing the Jersey implementation to comply with the specification javadocs.
        Hide
        Marek Potociar added a comment -

        When trying to build a new URI with unresolved template parameters, UriBuilder and LinkBuilder now throw IllegalArgumentException. WebTarget throws IllegalStateException that wraps the IAE thrown by internal UriBuilder.

        Show
        Marek Potociar added a comment - When trying to build a new URI with unresolved template parameters, UriBuilder and LinkBuilder now throw IllegalArgumentException. WebTarget throws IllegalStateException that wraps the IAE thrown by internal UriBuilder.
        Hide
        Stephan202 added a comment -

        I seems to me this ticket introduced a regression. Please have a look at JERSEY-2654.

        Show
        Stephan202 added a comment - I seems to me this ticket introduced a regression. Please have a look at JERSEY-2654 .

          People

          • Assignee:
            Marek Potociar
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: