Buggy code:
public abstract class MarkupContainer extends Component implements Iterable < Component > { private static final long serialVersionUID = 1L ; private static final Logger log = LoggerFactory . getLogger ( MarkupContainer . class ) ; private Object children ; public MarkupContainer ( final String id ) { } public MarkupContainer ( final String id , IModel < ? > model ) { } public MarkupContainer add ( final Component ... childs ) { } public MarkupContainer addOrReplace ( final Component ... childs ) { } public final boolean autoAdd ( final Component component , MarkupStream markupStream ) { } public boolean contains ( final Component component , final boolean recurse ) { } @ Override public final Component get ( final String path ) { } public MarkupStream getAssociatedMarkupStream ( final boolean throwException ) { } public Markup getAssociatedMarkup ( ) { } public IMarkupFragment getMarkup ( final Component child ) { } public MarkupType getMarkupType ( ) { } public void internalAdd ( final Component child ) { } public Iterator < Component > iterator ( ) { } public final Iterator < Component > iterator ( Comparator < Component > comparator ) { } public MarkupContainer remove ( final Component component ) { } public MarkupContainer remove ( final String id ) { } public MarkupContainer removeAll ( ) { if ( ( children ) != null ) { addStateChange ( ) ; int size = children_size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Object childObject = children_get ( i , false ) ; if ( childObject instanceof Component ) { final Component child = ( ( Component ) ( childObject ) ) ; child . internalOnRemove ( ) ; <START_BUG> child . detachModel ( ) ; <END_BUG> child . setParent ( null ) ; } } children = null ; } return this ; } public final void renderAssociatedMarkup ( final String openTagName , final String exceptionMessage ) { } public MarkupContainer replace ( final Component child ) { } @ Override public MarkupContainer setDefaultModel ( final IModel < ? > model ) { } public int size ( ) { } @ Override public String toString ( ) { } @ Override public String toString ( final boolean detailed ) { } public final < S extends Component , R > R visitChildren ( final Class < ? > clazz , final IVisitor < S , R > visitor ) { } public final < R > R visitChildren ( final IVisitor < Component , R > visitor ) { } public final ComponentHierarchyIterator visitChildren ( ) { } public final ComponentHierarchyIterator visitChildren ( final Class < ? > clazz ) { } private final void addedComponent ( final Component child ) { } @ Override public final void internalInitialize ( ) { } private final void children_add ( final Component child ) { } public final Component get ( int index ) { } private final Component children_get ( int index ) { } private final Object postprocess ( Object object , boolean reconstruct , MarkupContainer parent , int index ) { } private final Object children_get ( int index , boolean reconstruct ) { } private final String getId ( Object object ) { } private final Component children_get ( final String id ) { } private final int children_indexOf ( Component child ) { } private final Component children_remove ( Component component ) { } private final Component children_remove ( int index ) { } private final Object children_set ( int index , Object child , boolean reconstruct ) { } private final Component children_set ( int index , Component child ) { } private final int children_size ( ) { } private final Component put ( final Component child ) { } private final void removedComponent ( final Component component ) { } protected final boolean renderNext ( final MarkupStream markupStream ) { } private List < String > findSimilarComponents ( final String id ) { } @ Override public void onComponentTagBody ( final MarkupStream markupStream , final ComponentTag openTag ) { } @ Override protected void onRender ( ) { } private final void renderComponentTagBody ( final MarkupStream markupStream , final ComponentTag openTag ) { } protected final void renderAll ( final MarkupStream markupStream , final ComponentTag openTag ) { } private static class ComponentSourceEntry extends org . apache . wicket . ComponentSourceEntry { private ComponentSourceEntry ( MarkupContainer container , Component component , IComponentSource componentSource ) { } private static final long serialVersionUID = 1L ; @ Override protected void setChild ( MarkupContainer parent , int index , Component child ) { } } @ Override void removeChildren ( ) { } @ Override void detachChildren ( ) { } @ Override void internalMarkRendering ( boolean setRenderingFlag ) { } private Component [ ] copyChildren ( ) { } @ Override void onBeforeRenderChildren ( ) { } @ Override void onEnabledStateChanged ( ) { } @ Override void onVisibleStateChanged ( ) { } @ Override protected void onAfterRenderChildren ( ) { } public boolean hasAssociatedMarkup ( ) { } @ Override void setRenderAllowed ( ) { } private static class ChildList extends AbstractList < Object > implements IClusterable { private static final long serialVersionUID = - 7861580911447631127L ; private int size ; private Object [ ] childs ; public ChildList ( Object children ) { } @ Override public Object get ( int index ) { } @ Override public int size ( ) { } @ Override public boolean add ( Object o ) { } @ Override public void add ( int index , Object element ) { } @ Override public Object set ( int index , Object element ) { } @ Override public Object remove ( int index ) { } public void ensureCapacity ( int minCapacity ) { } } public final void swap ( int idx1 , int idx2 ) { }

Fix:
child . detach ( ) ;