Program: 32542
Project: 32542
Buggy source:
public MainPanel(){
  super(new BorderLayout());
  JTree tree=new JTree(){
    @Override public void updateUI(){
      setCellRenderer(null);
      setCellEditor(null);
      super.updateUI();
      setCellRenderer(new CheckBoxNodeRenderer());
      setCellEditor(new CheckBoxNodeEditor());
    }
  }
;
  TreeModel model=tree.getModel();
  DefaultMutableTreeNode root=(DefaultMutableTreeNode)model.getRoot();
  Enumeration e=root.breadthFirstEnumeration();
  while (e.hasMoreElements()) {
    DefaultMutableTreeNode node=(DefaultMutableTreeNode)e.nextElement();
    Object o=node.getUserObject();
    if (o instanceof String) {
      node.setUserObject(new CheckBoxNode((String)o,false));
    }
  }
  tree.setEditable(true);
  tree.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
  tree.expandRow(0);
  model.addTreeModelListener(new TreeModelListener(){
    private boolean adjusting=false;
    @Override public void treeNodesChanged(    TreeModelEvent e){
      if (adjusting)       return;
      adjusting=true;
      TreePath parent=e.getTreePath();
      Object[] children=e.getChildren();
      DefaultTreeModel model=(DefaultTreeModel)e.getSource();
      DefaultMutableTreeNode node;
      CheckBoxNode c;
      if (children != null && children.length == 1) {
        node=(DefaultMutableTreeNode)children[0];
        c=(CheckBoxNode)node.getUserObject();
        updateParentUserObject(model,(DefaultMutableTreeNode)parent.getLastPathComponent());
      }
 else {
        node=(DefaultMutableTreeNode)model.getRoot();
        c=(CheckBoxNode)node.getUserObject();
      }
      updateAllChildrenUserObject(model,node,c.selected);
      adjusting=false;
    }
    private void updateParentUserObject(    DefaultTreeModel model,    DefaultMutableTreeNode parent){
      CheckBoxNode check=(CheckBoxNode)parent.getUserObject();
      int selectedCount=0;
      java.util.Enumeration children=parent.children();
      while (children.hasMoreElements()) {
        DefaultMutableTreeNode node=(DefaultMutableTreeNode)children.nextElement();
        CheckBoxNode cbn=(CheckBoxNode)node.getUserObject();
        if (cbn.selected)         selectedCount++;
      }
      if (selectedCount == 0) {
        parent.setUserObject(new CheckBoxNode(check.str,false));
      }
 else       if (selectedCount == parent.getChildCount()) {
        parent.setUserObject(new CheckBoxNode(check.str,true));
      }
 else {
        parent.setUserObject(new CheckBoxNode(check.str));
      }
      model.nodeChanged(parent);
    }
    private void updateAllChildrenUserObject(    DefaultTreeModel model,    DefaultMutableTreeNode root,    boolean isSelected){
      java.util.Enumeration breadth=root.breadthFirstEnumeration();
      while (breadth.hasMoreElements()) {
        DefaultMutableTreeNode node=(DefaultMutableTreeNode)breadth.nextElement();
        if (root == node) {
          continue;
        }
        CheckBoxNode check=(CheckBoxNode)node.getUserObject();
        node.setUserObject(new CheckBoxNode(check.str,isSelected));
        model.nodeChanged(node);
      }
    }
    @Override public void treeNodesInserted(    TreeModelEvent e){
    }
    @Override public void treeNodesRemoved(    TreeModelEvent e){
    }
    @Override public void treeStructureChanged(    TreeModelEvent e){
    }
  }
);
  setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  add(new JScrollPane(tree));
  setPreferredSize(new Dimension(320,240));
}

Fixed version (ground truth):
public MainPanel(){
  super(new BorderLayout());
  JTree tree=new JTree(){
    @Override public void updateUI(){
      setCellRenderer(null);
      setCellEditor(null);
      super.updateUI();
      setCellRenderer(new CheckBoxNodeRenderer());
      setCellEditor(new CheckBoxNodeEditor());
    }
  }
;
  TreeModel model=tree.getModel();
  DefaultMutableTreeNode root=(DefaultMutableTreeNode)model.getRoot();
  Enumeration e=root.breadthFirstEnumeration();
  while (e.hasMoreElements()) {
    DefaultMutableTreeNode node=(DefaultMutableTreeNode)e.nextElement();
    Object o=node.getUserObject();
    if (o instanceof String) {
      node.setUserObject(new CheckBoxNode((String)o,Status.DESELECTED));
    }
  }
  tree.setEditable(true);
  tree.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
  tree.expandRow(0);
  model.addTreeModelListener(new TreeModelListener(){
    private boolean adjusting=false;
    @Override public void treeNodesChanged(    TreeModelEvent e){
      if (adjusting)       return;
      adjusting=true;
      TreePath parent=e.getTreePath();
      Object[] children=e.getChildren();
      DefaultTreeModel model=(DefaultTreeModel)e.getSource();
      DefaultMutableTreeNode node;
      CheckBoxNode c;
      if (children != null && children.length == 1) {
        node=(DefaultMutableTreeNode)children[0];
        c=(CheckBoxNode)node.getUserObject();
        DefaultMutableTreeNode n=(DefaultMutableTreeNode)parent.getLastPathComponent();
        while (n != null) {
          updateParentUserObject(n);
          DefaultMutableTreeNode tmp=(DefaultMutableTreeNode)n.getParent();
          if (tmp == null) {
            break;
          }
 else {
            n=tmp;
          }
        }
        model.nodeChanged(n);
      }
 else {
        node=(DefaultMutableTreeNode)model.getRoot();
        c=(CheckBoxNode)node.getUserObject();
      }
      updateAllChildrenUserObject(node,c.status);
      model.nodeChanged(node);
      adjusting=false;
    }
    private void updateParentUserObject(    DefaultMutableTreeNode parent){
      String label=((CheckBoxNode)parent.getUserObject()).label;
      int selectedCount=0;
      int indeterminateCount=0;
      java.util.Enumeration children=parent.children();
      while (children.hasMoreElements()) {
        DefaultMutableTreeNode node=(DefaultMutableTreeNode)children.nextElement();
        CheckBoxNode check=(CheckBoxNode)node.getUserObject();
        if (check.status == Status.INDETERMINATE) {
          indeterminateCount++;
          break;
        }
        if (check.status == Status.SELECTED)         selectedCount++;
      }
      if (indeterminateCount > 0) {
        parent.setUserObject(new CheckBoxNode(label));
      }
 else       if (selectedCount == 0) {
        parent.setUserObject(new CheckBoxNode(label,Status.DESELECTED));
      }
 else       if (selectedCount == parent.getChildCount()) {
        parent.setUserObject(new CheckBoxNode(label,Status.SELECTED));
      }
 else {
        parent.setUserObject(new CheckBoxNode(label));
      }
    }
    private void updateAllChildrenUserObject(    DefaultMutableTreeNode root,    Status status){
      java.util.Enumeration breadth=root.breadthFirstEnumeration();
      while (breadth.hasMoreElements()) {
        DefaultMutableTreeNode node=(DefaultMutableTreeNode)breadth.nextElement();
        if (root == node) {
          continue;
        }
        CheckBoxNode check=(CheckBoxNode)node.getUserObject();
        node.setUserObject(new CheckBoxNode(check.label,status));
      }
    }
    @Override public void treeNodesInserted(    TreeModelEvent e){
    }
    @Override public void treeNodesRemoved(    TreeModelEvent e){
    }
    @Override public void treeStructureChanged(    TreeModelEvent e){
    }
  }
);
  setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  add(new JScrollPane(tree));
  setPreferredSize(new Dimension(320,240));
}