Wicket
  1. Wicket
  2. WICKET-349

ListView can't undo changes to model

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.5, 1.2.6
    • Fix Version/s: 1.2.7, 1.3.0-beta4
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      WinXP, Tomcat 5.5.

      Description

      Given the code below (adapted from the guestbook example):

      Form form = new Form("form") {
      protected void onSubmit()

      { List comments = listView.getList(); listView.modelChanging(); comments.add(new Comment(comment, new Date())); comment = ""; listView.modelChanged(); }

      };

      Perform the steps:
      1) add "a" to the ListView and submit, bringing the page to version 1.
      2) add "b" to the ListView and submit, bringing the page to version 2.
      3) add "c" to the ListView and submit, bringing the page to version 3.
      4) press Back twice.
      5) add "x" to the ListView and submit. This will try to revert the page back to version 1. But it will fail with an IllegalStateException (full stack trace is shown below).

      This is because at step 3, the ListView contains two items: "a" and "b". Calling modelChanging() will store the model (a list containing "a" and "b") into a ModelChange object for later undo. The problem is, when this action is undone, ModelChange.undo() will call setModel() on the ListView, which will call removeAll() on itself. This will leave the ListView in a state different from the original (containing "a" and "b" items). This is not a problem if the ListView was to be rendered immediately (then it would create the items again). But in this case, the next step is to further undo the adding of item "b". However, the item's parent has just been set to null by removeAll(). This causes Component.remove() to throw an exception.

      Full stack trace is here:
      Unexpected RuntimeException

      Root cause:

      java.lang.IllegalStateException: Cannot remove [MarkupContainer [Component id = 1, page = <No Page>, path = 1.ListItem]] from null parent!
      at wicket.Component.remove(Component.java:1469)
      at wicket.version.undo.Add.undo(Add.java:81)
      at wicket.version.undo.ChangeList.undo(ChangeList.java:93)
      at wicket.version.undo.UndoPageVersionManager.undo(UndoPageVersionManager.java:217)
      at wicket.version.undo.UndoPageVersionManager.getVersion(UndoPageVersionManager.java:167)
      at wicket.Page.getVersion(Page.java:589)
      at wicket.PageMap.get(PageMap.java:461)
      at wicket.Session.getPage(Session.java:447)
      at wicket.request.compound.DefaultRequestTargetResolverStrategy.resolveRenderedPage(DefaultRequestTargetResolverStrategy.java:215)
      at wicket.request.compound.DefaultRequestTargetResolverStrategy.resolve(DefaultRequestTargetResolverStrategy.java:153)
      at wicket.request.compound.AbstractCompoundRequestCycleProcessor.resolve(AbstractCompoundRequestCycleProcessor.java:48)
      at wicket.RequestCycle.step(RequestCycle.java:992)
      at wicket.RequestCycle.steps(RequestCycle.java:1084)
      at wicket.RequestCycle.request(RequestCycle.java:454)
      at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:219)
      at wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:262)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)

        Activity

        Hide
        Kent Tong added a comment -

        This bug is still there in 1.2.6.

        Show
        Kent Tong added a comment - This bug is still there in 1.2.6.
        Hide
        Johan Compagner added a comment -

        in 1.3 with the SecondLevelCache this isn't a problem anymore
        will see if i can reproduce this in 1.2.6 and if this is also still a problem in 1.3 with AccessStack

        Show
        Johan Compagner added a comment - in 1.3 with the SecondLevelCache this isn't a problem anymore will see if i can reproduce this in 1.2.6 and if this is also still a problem in 1.3 with AccessStack
        Hide
        Johan Compagner added a comment -

        fixed it in both streams

        Show
        Johan Compagner added a comment - fixed it in both streams

          People

          • Assignee:
            Johan Compagner
            Reporter:
            Kent Tong
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development