Program: 32526
Project: 32526
Buggy source:
/** 
 * This test ensures that the SortedList sorts by its own order, then by the order in the source list.
 */
public void testSortedListHandlesSortEvents(){
  Comparator artistComparator=GlazedLists.beanPropertyComparator(Song.class,"String_Node_Str");
  Comparator songComparator=GlazedLists.beanPropertyComparator(Song.class,"String_Node_Str");
  List<Comparable> expectedOrder;
  sortedList.setComparator(null);
  SortedList sortedAgain=new SortedList<Comparable>(sortedList,artistComparator);
  ListConsistencyListener.install(sortedAgain);
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,artistComparator);
  assertEquals(expectedOrder,sortedAgain);
  sortedList.setComparator(songComparator);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,GlazedLists.chainComparators((List)Arrays.asList(new Comparator[]{artistComparator,songComparator})));
  assertEquals(expectedOrder,sortedAgain);
  sortedList.setComparator(null);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,artistComparator);
  assertEquals(expectedOrder,sortedAgain);
  unsortedList.clear();
  Random dice=new Random(0);
  List<String> artists=GlazedListsTests.stringToList("String_Node_Str");
  for (int a=0; a < 200; a++) {
    String randomArtist=artists.get(dice.nextInt(artists.size()));
    String randomSong=artists.get(dice.nextInt(artists.size()));
    unsortedList.add(new Song(randomArtist,randomSong));
  }
  sortedList.setComparator(songComparator);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,GlazedLists.chainComparators((List)Arrays.asList(new Comparator[]{artistComparator,songComparator})));
  assertEquals(expectedOrder,sortedAgain);
  sortedList.setComparator(null);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,artistComparator);
  assertEquals(expectedOrder,sortedAgain);
}

Fixed version (ground truth):
/** 
 * This test ensures that the SortedList sorts by its own order, then by the order in the source list.
 */
public void testSortedListHandlesSortEvents(){
  Comparator artistComparator=GlazedLists.beanPropertyComparator(Song.class,"String_Node_Str",new String[0]);
  Comparator songComparator=GlazedLists.beanPropertyComparator(Song.class,"String_Node_Str",new String[0]);
  List<Comparable> expectedOrder;
  sortedList.setComparator(null);
  SortedList sortedAgain=new SortedList<Comparable>(sortedList,artistComparator);
  ListConsistencyListener.install(sortedAgain);
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  unsortedList.add(new Song("String_Node_Str","String_Node_Str"));
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,artistComparator);
  assertEquals(expectedOrder,sortedAgain);
  sortedList.setComparator(songComparator);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,GlazedLists.chainComparators((List)Arrays.asList(new Comparator[]{artistComparator,songComparator})));
  assertEquals(expectedOrder,sortedAgain);
  sortedList.setComparator(null);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,artistComparator);
  assertEquals(expectedOrder,sortedAgain);
  unsortedList.clear();
  Random dice=new Random(0);
  List<String> artists=GlazedListsTests.stringToList("String_Node_Str");
  for (int a=0; a < 200; a++) {
    String randomArtist=artists.get(dice.nextInt(artists.size()));
    String randomSong=artists.get(dice.nextInt(artists.size()));
    unsortedList.add(new Song(randomArtist,randomSong));
  }
  sortedList.setComparator(songComparator);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,GlazedLists.chainComparators((List)Arrays.asList(new Comparator[]{artistComparator,songComparator})));
  assertEquals(expectedOrder,sortedAgain);
  sortedList.setComparator(null);
  expectedOrder=new ArrayList<Comparable>(unsortedList);
  Collections.sort(expectedOrder,artistComparator);
  assertEquals(expectedOrder,sortedAgain);
}