Program: 159482
Project: 159482
Buggy source:
@Override public void drawCards(SortSetting sortSetting,boolean piles){
  int maxWidth=this.getParent().getWidth();
  int numColumns=maxWidth / Config.dimensions.frameWidth;
  int curColumn=0;
  int curRow=0;
  if (cards.size() > 0) {
    Rectangle rectangle=new Rectangle(Config.dimensions.frameWidth,Config.dimensions.frameHeight);
    List<MageCard> sortedCards=new ArrayList<MageCard>(cards.values());
switch (sortSetting.getSortBy()) {
case NAME:
      Collections.sort(sortedCards,new CardNameComparator());
    break;
case RARITY:
  Collections.sort(sortedCards,new CardRarityComparator());
break;
case COLOR:
Collections.sort(sortedCards,new CardColorComparator());
break;
case COLOR_DETAILED:
Collections.sort(sortedCards,new CardColorDetailedComparator());
break;
case CASTING_COST:
Collections.sort(sortedCards,new CardCostComparator());
break;
}
MageCard lastCard=null;
for (MageCard cardImg : sortedCards) {
if (piles) {
if (lastCard == null) {
lastCard=cardImg;
}
switch (sortSetting.getSortBy()) {
case NAME:
if (!cardImg.getOriginal().getName().equals(lastCard.getOriginal().getName())) {
curColumn++;
curRow=0;
}
break;
case RARITY:
if (!cardImg.getOriginal().getRarity().equals(lastCard.getOriginal().getRarity())) {
curColumn++;
curRow=0;
}
break;
case COLOR:
if (cardImg.getOriginal().getColor().compareTo(lastCard.getOriginal().getColor()) != 0) {
curColumn++;
curRow=0;
}
break;
case COLOR_DETAILED:
if (cardImg.getOriginal().getColor().hashCode() != lastCard.getOriginal().getColor().hashCode()) {
curColumn++;
curRow=0;
}
break;
case CASTING_COST:
if (cardImg.getOriginal().getConvertedManaCost() != lastCard.getOriginal().getConvertedManaCost()) {
curColumn++;
curRow=0;
}
break;
}
rectangle.setLocation(curColumn * Config.dimensions.frameWidth,curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x,rectangle.y,Config.dimensions.frameWidth,Config.dimensions.frameHeight);
moveToFront(cardImg);
curRow++;
lastCard=cardImg;
}
 else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth,curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x,rectangle.y,Config.dimensions.frameWidth,Config.dimensions.frameHeight);
moveToFront(cardImg);
curColumn++;
if (curColumn == numColumns) {
curColumn=0;
curRow++;
}
}
}
}
resizeArea();
revalidate();
repaint();
}

Fixed version (ground truth):
@Override public void drawCards(SortSetting sortSetting){
  int maxWidth=this.getParent().getWidth();
  int numColumns=maxWidth / Config.dimensions.frameWidth;
  int curColumn=0;
  int curRow=0;
  if (cards.size() > 0) {
    Rectangle rectangle=new Rectangle(Config.dimensions.frameWidth,Config.dimensions.frameHeight);
    List<MageCard> sortedCards=new ArrayList<MageCard>(cards.values());
switch (sortSetting.getSortBy()) {
case NAME:
      Collections.sort(sortedCards,new CardNameComparator());
    break;
case RARITY:
  Collections.sort(sortedCards,new CardRarityComparator());
break;
case COLOR:
Collections.sort(sortedCards,new CardColorComparator());
break;
case COLOR_DETAILED:
Collections.sort(sortedCards,new CardColorDetailedComparator());
break;
case CASTING_COST:
Collections.sort(sortedCards,new CardCostComparator());
break;
}
MageCard lastCard=null;
for (MageCard cardImg : sortedCards) {
if (sortSetting.isPilesToggle()) {
if (lastCard == null) {
lastCard=cardImg;
}
switch (sortSetting.getSortBy()) {
case NAME:
if (!cardImg.getOriginal().getName().equals(lastCard.getOriginal().getName())) {
curColumn++;
curRow=0;
}
break;
case RARITY:
if (!cardImg.getOriginal().getRarity().equals(lastCard.getOriginal().getRarity())) {
curColumn++;
curRow=0;
}
break;
case COLOR:
if (cardImg.getOriginal().getColor().compareTo(lastCard.getOriginal().getColor()) != 0) {
curColumn++;
curRow=0;
}
break;
case COLOR_DETAILED:
if (cardImg.getOriginal().getColor().hashCode() != lastCard.getOriginal().getColor().hashCode()) {
curColumn++;
curRow=0;
}
break;
case CASTING_COST:
if (cardImg.getOriginal().getConvertedManaCost() != lastCard.getOriginal().getConvertedManaCost()) {
curColumn++;
curRow=0;
}
break;
}
rectangle.setLocation(curColumn * Config.dimensions.frameWidth,curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x,rectangle.y,Config.dimensions.frameWidth,Config.dimensions.frameHeight);
moveToFront(cardImg);
curRow++;
lastCard=cardImg;
}
 else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth,curRow * 20);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x,rectangle.y,Config.dimensions.frameWidth,Config.dimensions.frameHeight);
moveToFront(cardImg);
curColumn++;
if (curColumn == numColumns) {
curColumn=0;
curRow++;
}
}
}
}
resizeArea();
revalidate();
repaint();
}