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

wicket:border: inconsistency between add() and remove()

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5-RC4
    • Fix Version/s: 1.5-RC5
    • Component/s: wicket
    • Labels:
      None

      Description

      Assuming c1 is a Border and c2 is some component, the following sequence crashes with duplicate addition:

      c1.add(c2);
      c1.remove(c2);
      c1.add(c2);

      The reason for this is that remove() doesn't remove the object from the bodycontainer. The sequence can be made to work by changing the middle line to:

      c1.getBodyContainer().remove(c2);

      That remove() doesn't look the component from the same container as add() adds it to, seems to violate the principle of least astonishment. Unfortunately the Component structure manipulation API has more methods, such as swap(), size(), get(), etc. which are final, and can't be overridden by Border as they are. It could be best to force all users to use c1.getBodyContainer().add() instead of c1.add(), because consistent operation is probably easier to deal with in the long run than behavior that conforms to initial assumptions but has flaws elsewhere.

      This ticket suggests removing the overload of add() and documenting the difference in migration guide.

        Attachments

        1. wicket-3702.patch
          33 kB
          Martin Grigorov

          Activity

            People

            • Assignee:
              ivaynberg Igor Vaynberg
              Reporter:
              alankila Antti S. Lankila
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified