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

Inconsistent behavior id under special circumstances

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4.14, 1.4.15, 1.4.16, 1.4.17
    • 1.4.19
    • wicket
    • None

    Description

      When removing behaviors in org.apache.wicket.Component#removeBehavior under special circumstances ids of existing behaviors can change causing inconsistentencies.

      Ids of behaviors are determined by their position inside an array. The error occurs when you first remove a behavior in the middle of the array and then eventually at the end. The problem is some code that tries to compact the array under wrong assumpt when removing the last element in the array

      This is the code that displays it

      DummyBehavior dummyBehavior = new DummyBehavior();
      component.add(dummyBehavior);
      DummyBehavior dummyBehavior2 = new DummyBehavior();
      component.add(dummyBehavior2);
      DummyBehavior dummyBehavior3 = new DummyBehavior();
      component.add(dummyBehavior3);
      DummyBehavior dummyBehavior4 = new DummyBehavior();
      component.add(dummyBehavior4);

      String callbackUrlBefore = dummyBehavior3.getCallbackUrl().toString();
      component.remove(dummyBehavior2);
      String callbackUrlAfter2 = dummyBehavior3.getCallbackUrl().toString();
      Assert.assertEquals("Works fine", callbackUrlBefore, callbackUrlAfter2);

      component.remove(dummyBehavior4);
      String callbackUrlAfter4 = dummyBehavior3.getCallbackUrl().toString();
      Assert.assertEquals("Bug in Wicket!!!", callbackUrlBefore, callbackUrlAfter4);

      You can fix this by simple commenting out the compacting code. And live with an array that may grow a bit.

      This is the orginal code in org.apache.wicket.Component#removeBehavior now commented out

      // if (o instanceof IRequestListener) {
      // // this was a listener which mightve caused holes in the array, see if we
      // // can clean them up. notice: at this point we already know there are no
      // // listeners that can be affected by index change downstream because this is
      // // the last one in the array
      // for (int j = i - 1; j >= start; j--) {
      // if (data_get(j) == null)

      { // data_remove(j); // }

      // }
      // }

      Due to some larger refactoring this code does not seem to be present in 1.5.x any more.

      Attachments

        Activity

          People

            ivaynberg Igor Vaynberg
            ozeigermann Oliver Zeigermann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: