Program: 49973
Project: 49973
Buggy source:
/** 
 * Initialize components of the GUI Create all the GUI components, set their specific properties and add them to the  window. Also add any necessary ActionListeners.
 * @param whiteRules the rules for white team.
 * @param blackRules the rules for black team.
 */
private void initComponents(){
  setLayout(new FlowLayout());
  setBorder(BorderFactory.createLoweredBevelBorder());
  final Board[] boards=b.getBoards();
  final DefaultListModel list=new DefaultListModel();
  Object[] allPieces=PieceBuilder.getSet().toArray();
  for (int i=0; i < allPieces.length; i++) {
    list.addElement(allPieces[i]);
  }
  list.addElement("String_Node_Str");
  final JList piecesList=new JList(list);
  final Board bShowPiece=new Board(2,1,false);
  final JPanel showPiece=new JPanel();
  showPiece.setLayout(new GridLayout(2,1));
  showPiece.setPreferredSize(new Dimension(50,100));
  final JButton jb1=new JButton();
  final JButton jb2=new JButton();
  jb1.addActionListener(new SetUpListener(bShowPiece.getSquare(1,1)));
  bShowPiece.getSquare(1,1).setButton(jb1);
  bShowPiece.getSquare(2,1).setButton(jb2);
  showPiece.add(jb1);
  showPiece.add(jb2);
  bShowPiece.getSquare(1,1).refresh();
  bShowPiece.getSquare(2,1).refresh();
  piecesList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  piecesList.setLayoutOrientation(JList.VERTICAL);
  piecesList.setVisibleRowCount(-1);
  piecesList.setSelectedIndex(0);
  Piece toAdd=PieceBuilder.makePiece((String)list.elementAt(0),false,bShowPiece.getSquare(1,1),bShowPiece);
  Piece toAdd1=PieceBuilder.makePiece((String)list.elementAt(0),true,bShowPiece.getSquare(1,1),bShowPiece);
  bShowPiece.getSquare(1,1).setPiece(toAdd);
  bShowPiece.getSquare(2,1).setPiece(toAdd1);
  bShowPiece.getSquare(1,1).refresh();
  bShowPiece.getSquare(2,1).refresh();
  ListSelectionModel selectList=piecesList.getSelectionModel();
  final Color original=bShowPiece.getSquare(1,1).getColor();
  selectList.addListSelectionListener(new ListSelectionListener(){
    @Override public void valueChanged(    ListSelectionEvent e){
      ListSelectionModel lsm=(ListSelectionModel)e.getSource();
      int selection=lsm.getAnchorSelectionIndex();
      if (!lsm.getValueIsAdjusting()) {
        if (((String)list.elementAt(selection)).equals("String_Node_Str")) {
          bShowPiece.getSquare(1,1).setPiece(null);
          bShowPiece.getSquare(1,1).setBackgroundColor(original);
          bShowPiece.getSquare(1,1).setHabitable(true);
          bShowPiece.getSquare(1,1).refresh();
          jb1.setVisible(true);
          jb2.setVisible(false);
        }
 else         if (((String)list.elementAt(selection)).equals("String_Node_Str")) {
          bShowPiece.getSquare(1,1).refresh();
          jb2.setVisible(false);
          jb1.setVisible(false);
        }
 else {
          jb2.setVisible(true);
          jb1.setVisible(true);
          if (bShowPiece.getSquare(1,1).isHabitable() == false)           bShowPiece.getSquare(1,1).setHabitable(true);
          if (bShowPiece.getSquare(1,1).getColor().equals(original) == false)           bShowPiece.getSquare(1,1).setBackgroundColor(original);
          Piece toAdd=PieceBuilder.makePiece((String)list.elementAt(selection),false,bShowPiece.getSquare(1,1),bShowPiece);
          Piece toAdd1=PieceBuilder.makePiece((String)list.elementAt(selection),true,bShowPiece.getSquare(1,1),bShowPiece);
          bShowPiece.getSquare(1,1).setPiece(toAdd);
          bShowPiece.getSquare(2,1).setPiece(toAdd1);
          bShowPiece.getSquare(1,1).refresh();
          bShowPiece.getSquare(2,1).refresh();
        }
      }
    }
  }
);
  JScrollPane scrollPane=new JScrollPane(piecesList);
  scrollPane.setPreferredSize(new Dimension(200,200));
  for (int n=0; n < boards.length; n++) {
    final JPanel grid=new JPanel();
    grid.setLayout(new GridLayout(boards[n].numRows(),boards[n].numCols()));
    grid.setPreferredSize(new Dimension(boards[n].numCols() * 48,boards[n].numRows() * 48));
    int numRows=boards[n].numRows();
    int numCols=boards[n].numCols();
    for (int i=numRows; i > 0; i--) {
      for (int j=1; j <= numCols; j++) {
        JButton jb=new JButton();
        jb.addMouseListener(new SetUpMouseListener(boards[n].getSquare(i,j),boards[n],bShowPiece.getSquare(1,1)));
        boards[n].getSquare(i,j).setButton(jb);
        grid.add(jb);
        boards[n].getSquare(i,j).refresh();
      }
    }
    add(grid);
  }
  add(showPiece);
  add(scrollPane);
  backButton=new JButton("String_Node_Str");
  submitButton=new JButton("String_Node_Str");
  submitButton.addActionListener(new ActionListener(){
    @Override public void actionPerformed(    ActionEvent arg0){
      int numObjectives=0;
      if (!whiteRules.getObjectiveName().equals("String_Node_Str")) {
        for (        Piece p : whiteTeam) {
          if (p.getName().equals(whiteRules.getObjectiveName()))           numObjectives++;
        }
        if (numObjectives != 1) {
          JOptionPane.showMessageDialog(null,"String_Node_Str");
          return;
        }
      }
      numObjectives=0;
      if (!blackRules.getObjectiveName().equals("String_Node_Str")) {
        for (        Piece p : blackTeam) {
          if (p.getName().equals(blackRules.getObjectiveName()))           numObjectives++;
        }
        if (numObjectives != 1) {
          JOptionPane.showMessageDialog(null,"String_Node_Str");
          return;
        }
      }
      b.whiteTeam=whiteTeam;
      boolean set=false;
      for (      Piece p : whiteTeam) {
        if (p.getName().equals("String_Node_Str")) {
          whiteRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
          set=true;
          break;
        }
      }
      if (!set) {
        whiteRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
      }
      b.blackTeam=blackTeam;
      set=false;
      for (      Piece p : blackTeam) {
        if (p.getName().equals("String_Node_Str")) {
          blackRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
          set=true;
          break;
        }
      }
      if (!set) {
        blackRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
      }
      b.writeFile(whiteRules,blackRules);
      Driver.getInstance().revertPanel();
    }
  }
);
  JButton changePromote=new JButton("String_Node_Str");
  changePromote.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent arg0){
      promotion();
    }
  }
);
  JPanel options=new JPanel();
  options.setBorder(BorderFactory.createTitledBorder("String_Node_Str"));
  options.setLayout(new GridBagLayout());
  GridBagConstraints c=new GridBagConstraints();
  c.fill=GridBagConstraints.HORIZONTAL;
  c.gridx=0;
  c.gridy=1;
  options.add(changePromote,c);
  c.fill=GridBagConstraints.HORIZONTAL;
  c.gridx=0;
  c.gridy=2;
  options.add(submitButton,c);
  c.fill=GridBagConstraints.HORIZONTAL;
  c.gridx=0;
  c.gridy=3;
  options.add(backButton,c);
  add(options);
}

Fixed version (ground truth):
/** 
 * Initialize components of the GUI Create all the GUI components, set their specific properties and add them to the  window. Also add any necessary ActionListeners.
 * @param whiteRules the rules for white team.
 * @param blackRules the rules for black team.
 */
private void initComponents(){
  setLayout(new FlowLayout());
  setBorder(BorderFactory.createLoweredBevelBorder());
  final Board[] boards=b.getBoards();
  final DefaultListModel list=new DefaultListModel();
  Object[] allPieces=PieceBuilder.getSet().toArray();
  for (int i=0; i < allPieces.length; i++) {
    list.addElement(allPieces[i]);
  }
  list.addElement("String_Node_Str");
  final JList piecesList=new JList(list);
  final Board bShowPiece=new Board(2,1,false);
  final JPanel showPiece=new JPanel();
  showPiece.setLayout(new GridLayout(2,1));
  showPiece.setPreferredSize(new Dimension(50,100));
  final JButton jb1=new JButton();
  final JButton jb2=new JButton();
  jb1.addActionListener(new SetUpListener(bShowPiece.getSquare(1,1)));
  bShowPiece.getSquare(1,1).setButton(jb1);
  bShowPiece.getSquare(2,1).setButton(jb2);
  showPiece.add(jb1);
  showPiece.add(jb2);
  bShowPiece.getSquare(1,1).refresh();
  bShowPiece.getSquare(2,1).refresh();
  piecesList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  piecesList.setLayoutOrientation(JList.VERTICAL);
  piecesList.setVisibleRowCount(-1);
  piecesList.setSelectedIndex(0);
  Piece toAdd=PieceBuilder.makePiece((String)list.elementAt(0),false,bShowPiece.getSquare(1,1),bShowPiece);
  Piece toAdd1=PieceBuilder.makePiece((String)list.elementAt(0),true,bShowPiece.getSquare(1,1),bShowPiece);
  bShowPiece.getSquare(1,1).setPiece(toAdd);
  bShowPiece.getSquare(2,1).setPiece(toAdd1);
  bShowPiece.getSquare(1,1).refresh();
  bShowPiece.getSquare(2,1).refresh();
  ListSelectionModel selectList=piecesList.getSelectionModel();
  final Color original=bShowPiece.getSquare(1,1).getColor();
  selectList.addListSelectionListener(new ListSelectionListener(){
    @Override public void valueChanged(    ListSelectionEvent e){
      ListSelectionModel lsm=(ListSelectionModel)e.getSource();
      int selection=lsm.getAnchorSelectionIndex();
      if (!lsm.getValueIsAdjusting()) {
        if (((String)list.elementAt(selection)).equals("String_Node_Str")) {
          bShowPiece.getSquare(1,1).setPiece(null);
          bShowPiece.getSquare(1,1).setBackgroundColor(original);
          bShowPiece.getSquare(1,1).setHabitable(true);
          bShowPiece.getSquare(1,1).refresh();
          jb1.setVisible(true);
          jb2.setVisible(false);
        }
 else {
          jb2.setVisible(true);
          jb1.setVisible(true);
          if (bShowPiece.getSquare(1,1).isHabitable() == false)           bShowPiece.getSquare(1,1).setHabitable(true);
          if (bShowPiece.getSquare(1,1).getColor().equals(original) == false)           bShowPiece.getSquare(1,1).setBackgroundColor(original);
          Piece toAdd=PieceBuilder.makePiece((String)list.elementAt(selection),false,bShowPiece.getSquare(1,1),bShowPiece);
          Piece toAdd1=PieceBuilder.makePiece((String)list.elementAt(selection),true,bShowPiece.getSquare(1,1),bShowPiece);
          bShowPiece.getSquare(1,1).setPiece(toAdd);
          bShowPiece.getSquare(2,1).setPiece(toAdd1);
          bShowPiece.getSquare(1,1).refresh();
          bShowPiece.getSquare(2,1).refresh();
        }
      }
    }
  }
);
  JScrollPane scrollPane=new JScrollPane(piecesList);
  scrollPane.setPreferredSize(new Dimension(200,200));
  for (int n=0; n < boards.length; n++) {
    final JPanel grid=new JPanel();
    grid.setLayout(new GridLayout(boards[n].numRows(),boards[n].numCols()));
    grid.setPreferredSize(new Dimension(boards[n].numCols() * 48,boards[n].numRows() * 48));
    int numRows=boards[n].numRows();
    int numCols=boards[n].numCols();
    for (int i=numRows; i > 0; i--) {
      for (int j=1; j <= numCols; j++) {
        JButton jb=new JButton();
        jb.addMouseListener(new SetUpMouseListener(boards[n].getSquare(i,j),boards[n],bShowPiece.getSquare(1,1)));
        boards[n].getSquare(i,j).setButton(jb);
        grid.add(jb);
        boards[n].getSquare(i,j).refresh();
      }
    }
    add(grid);
  }
  add(showPiece);
  add(scrollPane);
  backButton=new JButton("String_Node_Str");
  submitButton=new JButton("String_Node_Str");
  submitButton.addActionListener(new ActionListener(){
    @Override public void actionPerformed(    ActionEvent arg0){
      int numObjectives=0;
      if (!whiteRules.getObjectiveName().equals("String_Node_Str")) {
        for (        Piece p : whiteTeam) {
          if (p.getName().equals(whiteRules.getObjectiveName()))           numObjectives++;
        }
        if (numObjectives != 1) {
          JOptionPane.showMessageDialog(null,"String_Node_Str");
          return;
        }
      }
      numObjectives=0;
      if (!blackRules.getObjectiveName().equals("String_Node_Str")) {
        for (        Piece p : blackTeam) {
          if (p.getName().equals(blackRules.getObjectiveName()))           numObjectives++;
        }
        if (numObjectives != 1) {
          JOptionPane.showMessageDialog(null,"String_Node_Str");
          return;
        }
      }
      b.whiteTeam=whiteTeam;
      boolean set=false;
      for (      Piece p : whiteTeam) {
        if (p.getName().equals("String_Node_Str")) {
          whiteRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
          set=true;
          break;
        }
      }
      if (!set) {
        whiteRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
      }
      b.blackTeam=blackTeam;
      set=false;
      for (      Piece p : blackTeam) {
        if (p.getName().equals("String_Node_Str")) {
          blackRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
          set=true;
          break;
        }
      }
      if (!set) {
        blackRules.setObjectivePiece(new ObjectivePiece("String_Node_Str","String_Node_Str"));
      }
      b.writeFile(whiteRules,blackRules);
      Driver.getInstance().revertPanel();
    }
  }
);
  JButton changePromote=new JButton("String_Node_Str");
  changePromote.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent arg0){
      promotion();
    }
  }
);
  JPanel options=new JPanel();
  options.setBorder(BorderFactory.createTitledBorder("String_Node_Str"));
  options.setLayout(new GridBagLayout());
  GridBagConstraints c=new GridBagConstraints();
  c.fill=GridBagConstraints.HORIZONTAL;
  c.gridx=0;
  c.gridy=1;
  options.add(changePromote,c);
  c.fill=GridBagConstraints.HORIZONTAL;
  c.gridx=0;
  c.gridy=2;
  options.add(submitButton,c);
  c.fill=GridBagConstraints.HORIZONTAL;
  c.gridx=0;
  c.gridy=3;
  options.add(backButton,c);
  add(options);
}