Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4637

HeaderBufferingWebResponse#writeMetaData(WebResponse) throws ConcurrentModificationException when invoked in a link handler

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 1.5.7
    • None
    • wicket

    Description

      This ticket follows from the email thread http://markmail.org/thread/uk5y4ddoopntmkgd

      I use the following ReplaceHandlerException to trigger a redirect which restarts the response but does not discard the response's meta data (e.g. cookies).

      /**

      • Response restarting exception which does not reset the header meta data.
        */
        public class NonResettingRestartException extends ReplaceHandlerException {

      public NonResettingRestartException(final Class<? extends Page> pageClass,
      final PageParameters params, final RequestCycle cycle) {
      super(createRequestHandler(pageClass, params), true);

      Response response = cycle.getResponse();
      if (response instanceof IMetaDataBufferingWebResponse)

      { IMetaDataBufferingWebResponse bufferingWebResponse = (IMetaDataBufferingWebResponse) response; WebResponse originalResponse = (WebResponse) cycle .getOriginalResponse(); bufferingWebResponse.writeMetaData(originalResponse); }

      }

      private static IRequestHandler createRequestHandler(
      Class<? extends Page> pageClass, PageParameters params)

      { return new RenderPageRequestHandler(new PageProvider(pageClass, params)); }

      }

      When this exception is thrown from a link handler, a ConcurrentModificationException occurs with the following stack trace:
      HeaderBufferingWebResponse.addCookie(Cookie) line: 72
      BufferedWebResponse$AddCookieAction.invoke(WebResponse) line: 240
      BufferedWebResponse.writeMetaData(WebResponse) line: 75
      HeaderBufferingWebResponse.writeMetaData(WebResponse) line: 205
      NonResettingRestartException.<init>(Class<Page>, PageParameters, RequestCycle) line: 28
      LinkPage$4.onClick() line: 38

      Analysis:
      1) HeaderBufferingWebResponse delegates #writeMetaData() to its bufferedResponse (a BufferedWebResponse instance).
      2) BufferedWebResponse iterates its action list with the single "AddCookieAction" and invoke()s it
      3) BufferedWebResponse$AddCookieAction.invoke does "response.addCookie(cookie)"
      4) The addCookie is executed with this==BufferedWebResponse from 2) which modifies the action list illegally

      Attachments

        1. wicket-4637.zip
          34 kB
          Bertrand Guay-Paquet
        2. wicket-4637_2.zip
          34 kB
          Bertrand Guay-Paquet

        Activity

          People

            Unassigned Unassigned
            berniegp Bertrand Guay-Paquet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: