Buggy code:
public abstract class AbstractTree extends Panel implements TreeModelListener , AjaxRequestTarget . ITargetRespondListener , ITreeStateListener { private static final long serialVersionUID = 1L ; private static interface IItemCallback { void visitItem ( AbstractTree . TreeItem item ) { } } private final class TreeItem extends WebMarkupContainer { private static final int FLAG_RENDER_CHILDREN = FLAG_RESERVED8 ; private static final long serialVersionUID = 1L ; private List < AbstractTree . TreeItem > children = null ; private final int level ; private final AbstractTree . TreeItem parent ; public TreeItem ( AbstractTree . TreeItem parent , String id , final Object node , int level ) { } public AbstractTree . TreeItem getParentItem ( ) { } public List < AbstractTree . TreeItem > getChildren ( ) { } public int getLevel ( ) { } @ Override public String getMarkupId ( ) { } public void setChildren ( List < AbstractTree . TreeItem > children ) { } protected final boolean isRenderChildren ( ) { } @ Override protected void onRender ( final MarkupStream markupStream ) { } @ Override public void renderHead ( final HtmlHeaderContainer container ) { } protected final void setRenderChildren ( boolean value ) { } @ Override protected void onDetach ( ) { } @ Override protected void onBeforeRender ( ) { } @ Override protected void onAfterRender ( ) { } } private class TreeItemContainer extends WebMarkupContainer { private static final long serialVersionUID = 1L ; public TreeItemContainer ( String id ) { } @ Override public void remove ( Component component ) { } @ Override protected void onRender ( final MarkupStream markupStream ) { } } private boolean attached = false ; private final AppendingStringBuffer deleteIds = new AppendingStringBuffer ( ) ; private boolean dirtyAll = false ; private final List < AbstractTree . TreeItem > dirtyItems = new ArrayList < AbstractTree . TreeItem > ( ) ; private final List < AbstractTree . TreeItem > dirtyItemsCreateDOM = new ArrayList < AbstractTree . TreeItem > ( ) ; private int idCounter = 0 ; private AbstractTree . TreeItemContainer itemContainer ; private final Map < Object , AbstractTree . TreeItem > nodeToItemMap = new HashMap < Object , AbstractTree . TreeItem > ( ) ; private TreeModel previousModel = null ; private AbstractTree . TreeItem rootItem = null ; private boolean rootLess = false ; private ITreeState state ; public AbstractTree ( String id ) { } public AbstractTree ( String id , IModel model ) { } public final void allNodesCollapsed ( ) { } public final void allNodesExpanded ( ) { } public ITreeState getTreeState ( ) { } protected void onBeforeAttach ( ) { } private void onBeforeRenderInternal ( ) { } @ Override public void onBeforeRender ( ) { } @ Override public void onDetach ( ) { } public final void invalidateAll ( ) { } public final boolean isRootLess ( ) { } public final void nodeCollapsed ( Object node ) { } public final void nodeExpanded ( Object node ) { } public final void nodeSelected ( Object node ) { } public final void nodeUnselected ( Object node ) { } protected boolean isForceRebuildOnSelectionChange ( ) { } public void setRootLess ( boolean rootLess ) { } public final void treeNodesChanged ( TreeModelEvent e ) { } private void markTheLastButOneChildDirty ( AbstractTree . TreeItem parent , AbstractTree . TreeItem child ) { } public final void treeNodesInserted ( TreeModelEvent e ) { } public final void treeNodesRemoved ( TreeModelEvent e ) { Object parent = e . getTreePath ( ) . getLastPathComponent ( ) ; AbstractTree . TreeItem parentItem = nodeToItemMap . get ( parent ) ; <START_BUG> if ( ( isNodeVisible ( parent ) ) && ( isNodeExpanded ( parent ) ) ) { <END_BUG> boolean nonEmpty = ! ( parentItem . getChildren ( ) . isEmpty ( ) ) ; for ( int i = 0 ; i < ( e . getChildren ( ) . length ) ; ++ i ) { Object node = e . getChildren ( ) [ i ] ; AbstractTree . TreeItem item = nodeToItemMap . get ( node ) ; if ( item != null ) { markTheLastButOneChildDirty ( parentItem , item ) ; parentItem . getChildren ( ) . remove ( item ) ; visitItemChildren ( item , new AbstractTree . IItemCallback ( ) { public void visitItem ( AbstractTree . TreeItem item ) { removeItem ( item ) ; getTreeState ( ) . selectNode ( item . getDefaultModelObject ( ) , false ) ; } } ) ; getTreeState ( ) . selectNode ( item . getDefaultModelObject ( ) , false ) ; removeItem ( item ) ; } } if ( nonEmpty && ( parentItem . getChildren ( ) . isEmpty ( ) ) ) { invalidateNode ( parent , true ) ; } } } public final void treeStructureChanged ( TreeModelEvent e ) { } public final void updateTree ( ) { } protected void addComponent ( AjaxRequestTarget target , Component component ) { } public void onTargetRespond ( AjaxRequestTarget target ) { } public final void updateTree ( final AjaxRequestTarget target ) { } protected final boolean isNodeExpanded ( Object node ) { } protected ITreeState newTreeState ( ) { } @ Override protected void onAfterRender ( ) { } protected abstract void populateTreeItem ( WebMarkupContainer item , int level ) { } private final void buildItemChildren ( AbstractTree . TreeItem item ) { } private final List < AbstractTree . TreeItem > buildTreeItems ( AbstractTree . TreeItem parent , Iterator < Object > nodes , int level ) { } private final void checkModel ( ) { } private final void clearAllItem ( ) { } private String getElementsDeleteJavascript ( ) { } private String getShortItemId ( AbstractTree . TreeItem item ) { } private static final ResourceReference JAVASCRIPT = new JavascriptResourceReference ( AbstractTree . class , "res//tree.js" ) ; private final void init ( ) { }

Fix:
if ( ( ( parentItem != null ) && ( isNodeVisible ( parent ) ) ) && ( isNodeExpanded ( parent ) ) ) {