Wicket
  1. Wicket
  2. WICKET-5073

UrlRenderer#removeCommonPrefixes() fails when contextPath+filterPrefix has more segments than the argument

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.6.0
    • Fix Version/s: 6.7.0, 1.5.11
    • Component/s: wicket
    • Labels:
      None

      Description

      I get this exception when trying to create a URL with RequestCycle#urlFor:

      org.apache.wicket.WicketRuntimeException: An error occurred while generating an Url for handler 'ResourceReferenceRequestHandler

      {resourceReference=scope: org.apache.wicket.Application; name: ImageResource; locale: null; style: null; variation: null, pageParameters=publicId=[f74df62d-cbdb-49db-96e4-36e3ea62610e], type=[sr]}

      '
      at org.apache.wicket.request.cycle.RequestCycle.urlFor(RequestCycle.java:516) [wicket-core-6.6.0.jar:6.6.0]
      at org.apache.wicket.request.cycle.RequestCycle.urlFor(RequestCycle.java:473) [wicket-core-6.6.0.jar:6.6.0]
      at xxx.XXXWebApplication.urlFor(XXXWebApplication.java:161) ~[xxx-web-0.1.0-SNAPSHOT.jar:0.1.0-SNAPSHOT]
      [...]
      Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      at java.util.ArrayList.rangeCheck(ArrayList.java:604) ~[na:1.7.0_10]
      at java.util.ArrayList.remove(ArrayList.java:445) ~[na:1.7.0_10]
      at org.apache.wicket.request.UrlRenderer.removeCommonPrefixes(UrlRenderer.java:319) ~[wicket-request-6.6.0.jar:6.6.0]
      at org.apache.wicket.request.UrlRenderer.renderRelativeUrl(UrlRenderer.java:220) ~[wicket-request-6.6.0.jar:6.6.0]
      at org.apache.wicket.request.UrlRenderer.renderUrl(UrlRenderer.java:117) ~[wicket-request-6.6.0.jar:6.6.0]
      at org.apache.wicket.request.cycle.RequestCycle.renderUrl(RequestCycle.java:529) [wicket-core-6.6.0.jar:6.6.0]
      at org.apache.wicket.request.cycle.RequestCycle.urlFor(RequestCycle.java:511) [wicket-core-6.6.0.jar:6.6.0]
      ... 46 common frames omitted

      The app uses a context path and no filter path. I see that UrlRenderer#removeCommonPrefixes receives an empty list and the code in the method assumes that context path + filter path is always a common prefix and tries to remove it later from the empty list.

        Activity

        Hide
        Sven Meier added a comment -

        I see two checks on #isEmpty() in removeCommonPrefixes(). Could you provide a quickstart or preferably an addition to UrlRendererTest?

        Show
        Sven Meier added a comment - I see two checks on #isEmpty() in removeCommonPrefixes(). Could you provide a quickstart or preferably an addition to UrlRendererTest?
        Hide
        Christoph Leiter added a comment -

        Unfortunately I wasn't able to reproduce this without the select2 component, but the quickstart itself is very simple. I suspect the problem is that urlFor is called in the IResourceListener callback.

        Then context path for the quickstart is "/qs" - the problem doesn't occur if it is set to "/".

        Show
        Christoph Leiter added a comment - Unfortunately I wasn't able to reproduce this without the select2 component, but the quickstart itself is very simple. I suspect the problem is that urlFor is called in the IResourceListener callback. Then context path for the quickstart is "/qs" - the problem doesn't occur if it is set to "/".

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Christoph Leiter
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development