Program: 152063
Project: 152063
Buggy source:
/** 
 * Creates a new config tree to display the configurations in the specified group.
 * @param editable if true, the tree will allow editing the configurations (only allowed fortrees depicting a single group).
 */
protected ConfigTree(ConfigGroup[] groups,boolean editable){
  @SuppressWarnings("String_Node_Str") ConfigGroup<ManagedConfig>[] mgroups=(ConfigGroup<ManagedConfig>[])groups;
  _groups=mgroups;
  setModel(new DefaultTreeModel(new ConfigTreeNode(null,null),true){
    public void valueForPathChanged(    TreePath path,    Object newValue){
      TreePath selection=getSelectionPath();
      ConfigTreeNode node=(ConfigTreeNode)path.getLastPathComponent();
      ConfigTreeNode parent=(ConfigTreeNode)node.getParent();
      removeNodeFromParent(node);
      node.setUserObject(parent.findNameForChild((String)newValue));
      insertNodeInto(node,parent,parent.getInsertionIndex(node));
      node.expandPaths(ConfigTree.this);
      setSelectionPath(selection);
    }
    public void insertNodeInto(    MutableTreeNode child,    MutableTreeNode parent,    int index){
      super.insertNodeInto(child,parent,index);
      if (!_block.enter()) {
        return;
      }
      try {
        ((ConfigTreeNode)child).addConfigs(_groups[0]);
      }
  finally {
        _block.leave();
      }
    }
    public void removeNodeFromParent(    MutableTreeNode node){
      ConfigTreeNode ctnode=(ConfigTreeNode)node;
      if (removeExpanded(ctnode)) {
        writeExpanded();
      }
      super.removeNodeFromParent(node);
      if (!_block.enter()) {
        return;
      }
      try {
        ctnode.removeConfigs(_groups[0]);
      }
  finally {
        _block.leave();
      }
    }
  }
);
  setRootVisible(false);
  setEditable(editable);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  addTreeSelectionListener(new TreeSelectionListener(){
    public void valueChanged(    TreeSelectionEvent event){
      ConfigTreeNode node=getSelectedNode();
      ManagedConfig config=(node == null) ? null : node.getConfig();
      if (_lconfig != null) {
        _lconfig.removeListener(ConfigTree.this);
      }
      if ((_lconfig=config) != null) {
        _lconfig.addListener(ConfigTree.this);
      }
    }
  }
);
  addTreeExpansionListener(new TreeExpansionListener(){
    public void treeExpanded(    TreeExpansionEvent event){
      ConfigTreeNode node=(ConfigTreeNode)event.getPath().getLastPathComponent();
      node.setExpanded(true);
      addExpanded(node.getName());
      node.expandPaths(ConfigTree.this);
    }
    public void treeCollapsed(    TreeExpansionEvent event){
      ConfigTreeNode node=(ConfigTreeNode)event.getPath().getLastPathComponent();
      node.setExpanded(false);
      removeExpanded(node.getName());
    }
  }
);
  setDragEnabled(true);
  setTransferHandler(new TransferHandler(){
    public int getSourceActions(    JComponent comp){
      return MOVE;
    }
    public boolean canImport(    JComponent comp,    DataFlavor[] flavors){
      return isEditable() && ListUtil.contains(flavors,ToolUtil.SERIALIZED_WRAPPED_FLAVOR);
    }
    public boolean importData(    JComponent comp,    Transferable t){
      boolean local=t.isDataFlavorSupported(LOCAL_NODE_TRANSFER_FLAVOR);
      Object data;
      try {
        data=t.getTransferData(local ? LOCAL_NODE_TRANSFER_FLAVOR : ToolUtil.SERIALIZED_WRAPPED_FLAVOR);
      }
 catch (      Exception e) {
        log.warning("String_Node_Str",e);
        return false;
      }
      ConfigTreeNode node, onode=null;
      if (local) {
        NodeTransfer transfer=(NodeTransfer)data;
        node=transfer.cnode;
        onode=transfer.onode;
      }
 else {
        data=((SerializableWrapper)data).getObject();
        if (!(data instanceof ConfigTreeNode)) {
          return false;
        }
        node=(ConfigTreeNode)data;
      }
      if (!node.verifyConfigClass(_groups[0].getConfigClass())) {
        return false;
      }
      ConfigTreeNode snode=getSelectedNode();
      ConfigTreeNode parent=(ConfigTreeNode)getModel().getRoot();
      if (snode != null && snode.getParent() != null) {
        parent=snode.getAllowsChildren() ? snode : (ConfigTreeNode)snode.getParent();
      }
      if (onode == parent || (onode != null && onode.getParent() == parent)) {
        return false;
      }
      node=(ConfigTreeNode)node.clone();
      String name=(String)node.getUserObject();
      node.setUserObject(parent.findNameForChild(name));
      if (onode != null && onode.getRoot() == parent.getRoot()) {
        ((DefaultTreeModel)getModel()).removeNodeFromParent(onode);
      }
      ((DefaultTreeModel)getModel()).insertNodeInto(node,parent,parent.getInsertionIndex(node));
      node.expandPaths(ConfigTree.this);
      setSelectionPath(new TreePath(node.getPath()));
      return true;
    }
    protected Transferable createTransferable(    JComponent c){
      ConfigTreeNode node=getSelectedNode();
      return (node == null) ? null : new NodeTransfer(node,false);
    }
    protected void exportDone(    JComponent source,    Transferable data,    int action){
      if (action == MOVE) {
        ConfigTreeNode onode=((NodeTransfer)data).onode;
        if (onode.getParent() != null) {
          ((DefaultTreeModel)getModel()).removeNodeFromParent(onode);
        }
      }
    }
  }
);
  ConfigTreeNode root=(ConfigTreeNode)getModel().getRoot();
  for (  ConfigGroup<ManagedConfig> group : _groups) {
    for (    ManagedConfig config : group.getConfigs()) {
      root.insertConfig(config,config.getName());
    }
    group.addListener(this);
  }
  ((DefaultTreeModel)getModel()).reload();
  root.setExpanded(true);
  String names=_prefs.get(_groups[0].getName() + "String_Node_Str",null);
  if (names == null) {
    root.expandPaths(this,1);
  }
 else {
    for (    String name : StringUtil.parseStringArray(names)) {
      ConfigTreeNode node=root.getNode(name);
      if (node != null) {
        _expanded.add(name);
        node.setExpanded(true);
      }
    }
    root.expandPaths(this);
  }
}

Fixed version (ground truth):
/** 
 * Creates a new config tree to display the configurations in the specified group.
 * @param editable if true, the tree will allow editing the configurations (only allowed fortrees depicting a single group).
 */
protected ConfigTree(ConfigGroup[] groups,boolean editable){
  @SuppressWarnings("String_Node_Str") ConfigGroup<ManagedConfig>[] mgroups=(ConfigGroup<ManagedConfig>[])groups;
  _groups=mgroups;
  setModel(new DefaultTreeModel(new ConfigTreeNode(null,null),true){
    public void valueForPathChanged(    TreePath path,    Object newValue){
      TreePath selection=getSelectionPath();
      ConfigTreeNode node=(ConfigTreeNode)path.getLastPathComponent();
      ConfigTreeNode parent=(ConfigTreeNode)node.getParent();
      removeNodeFromParent(node);
      node.setUserObject(parent.findNameForChild((String)newValue));
      insertNodeInto(node,parent,parent.getInsertionIndex(node));
      node.expandPaths(ConfigTree.this);
      setSelectionPath(selection);
    }
    public void insertNodeInto(    MutableTreeNode child,    MutableTreeNode parent,    int index){
      super.insertNodeInto(child,parent,index);
      if (!_block.enter()) {
        return;
      }
      try {
        ((ConfigTreeNode)child).addConfigs(_groups[0]);
      }
  finally {
        _block.leave();
      }
    }
    public void removeNodeFromParent(    MutableTreeNode node){
      ConfigTreeNode ctnode=(ConfigTreeNode)node;
      if (removeExpanded(ctnode)) {
        writeExpanded();
      }
      super.removeNodeFromParent(node);
      if (!_block.enter()) {
        return;
      }
      try {
        ctnode.removeConfigs(_groups[0]);
      }
  finally {
        _block.leave();
      }
    }
  }
);
  setRootVisible(false);
  setEditable(editable);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  addTreeSelectionListener(new TreeSelectionListener(){
    public void valueChanged(    TreeSelectionEvent event){
      ConfigTreeNode node=getSelectedNode();
      ManagedConfig config=(node == null) ? null : node.getConfig();
      if (_lconfig != null) {
        _lconfig.removeListener(ConfigTree.this);
      }
      if ((_lconfig=config) != null) {
        _lconfig.addListener(ConfigTree.this);
      }
    }
  }
);
  addTreeExpansionListener(new TreeExpansionListener(){
    public void treeExpanded(    TreeExpansionEvent event){
      ConfigTreeNode node=(ConfigTreeNode)event.getPath().getLastPathComponent();
      node.setExpanded(true);
      addExpanded(node.getName());
      node.expandPaths(ConfigTree.this);
    }
    public void treeCollapsed(    TreeExpansionEvent event){
      ConfigTreeNode node=(ConfigTreeNode)event.getPath().getLastPathComponent();
      node.setExpanded(false);
      removeExpanded(node.getName());
    }
  }
);
  setDragEnabled(true);
  setTransferHandler(new TransferHandler(){
    public int getSourceActions(    JComponent comp){
      return isEditable() ? MOVE : COPY;
    }
    public boolean canImport(    JComponent comp,    DataFlavor[] flavors){
      return isEditable() && ListUtil.contains(flavors,ToolUtil.SERIALIZED_WRAPPED_FLAVOR);
    }
    public boolean importData(    JComponent comp,    Transferable t){
      if (!canImport(comp,t.getTransferDataFlavors())) {
        return false;
      }
      boolean local=t.isDataFlavorSupported(LOCAL_NODE_TRANSFER_FLAVOR);
      Object data;
      try {
        data=t.getTransferData(local ? LOCAL_NODE_TRANSFER_FLAVOR : ToolUtil.SERIALIZED_WRAPPED_FLAVOR);
      }
 catch (      Exception e) {
        log.warning("String_Node_Str",e);
        return false;
      }
      ConfigTreeNode node, onode=null;
      if (local) {
        NodeTransfer transfer=(NodeTransfer)data;
        node=transfer.cnode;
        onode=transfer.onode;
      }
 else {
        data=((SerializableWrapper)data).getObject();
        if (!(data instanceof ConfigTreeNode)) {
          return false;
        }
        node=(ConfigTreeNode)data;
      }
      if (!node.verifyConfigClass(_groups[0].getConfigClass())) {
        return false;
      }
      ConfigTreeNode snode=getSelectedNode();
      ConfigTreeNode parent=(ConfigTreeNode)getModel().getRoot();
      if (snode != null && snode.getParent() != null) {
        parent=snode.getAllowsChildren() ? snode : (ConfigTreeNode)snode.getParent();
      }
      if (onode == parent || (onode != null && onode.getParent() == parent)) {
        return false;
      }
      node=(ConfigTreeNode)node.clone();
      String name=(String)node.getUserObject();
      node.setUserObject(parent.findNameForChild(name));
      if (onode != null && onode.getRoot() == parent.getRoot()) {
        ((DefaultTreeModel)getModel()).removeNodeFromParent(onode);
      }
      ((DefaultTreeModel)getModel()).insertNodeInto(node,parent,parent.getInsertionIndex(node));
      node.expandPaths(ConfigTree.this);
      setSelectionPath(new TreePath(node.getPath()));
      return true;
    }
    protected Transferable createTransferable(    JComponent c){
      ConfigTreeNode node=getSelectedNode();
      return (node == null) ? null : new NodeTransfer(node,false);
    }
    protected void exportDone(    JComponent source,    Transferable data,    int action){
      if (action == MOVE) {
        ConfigTreeNode onode=((NodeTransfer)data).onode;
        if (onode.getParent() != null) {
          ((DefaultTreeModel)getModel()).removeNodeFromParent(onode);
        }
      }
    }
  }
);
  ConfigTreeNode root=(ConfigTreeNode)getModel().getRoot();
  for (  ConfigGroup<ManagedConfig> group : _groups) {
    for (    ManagedConfig config : group.getConfigs()) {
      root.insertConfig(config,config.getName());
    }
    group.addListener(this);
  }
  ((DefaultTreeModel)getModel()).reload();
  root.setExpanded(true);
  String names=_prefs.get(_groups[0].getName() + "String_Node_Str",null);
  if (names == null) {
    root.expandPaths(this,1);
  }
 else {
    for (    String name : StringUtil.parseStringArray(names)) {
      ConfigTreeNode node=root.getNode(name);
      if (node != null) {
        _expanded.add(name);
        node.setExpanded(true);
      }
    }
    root.expandPaths(this);
  }
}