Program: 32426
Project: 32426
Buggy source:
/** 
 * Handle changes from the   {@link SortedList} by modifying the grouping state.During this method, callbacks will be made to the  {@link Client} who isresponsible for firing the appropriate change events to its listeners.
 */
public void listChanged(ListEvent<E> listChanges){
  final Barcode toDoList=new Barcode();
  toDoList.addWhite(0,barcode.size());
  final LinkedList removedValues=new LinkedList();
  int lastFakedUniqueChangeIndex=-1;
  while (listChanges.next()) {
    final int changeIndex=listChanges.getIndex();
    final int changeType=listChanges.getType();
    if (changeType == ListEvent.INSERT) {
      barcode.add(changeIndex,UNIQUE,1);
      toDoList.add(changeIndex,TODO,1);
    }
 else     if (changeType == ListEvent.UPDATE) {
      if (barcode.get(changeIndex) == UNIQUE) {
        if (changeIndex + 1 < barcode.size() && barcode.get(changeIndex + 1) == DUPLICATE) {
          if (changeIndex != lastFakedUniqueChangeIndex) {
            barcode.set(changeIndex,UNIQUE,2);
            toDoList.set(changeIndex,TODO,1);
            lastFakedUniqueChangeIndex=changeIndex + 1;
          }
        }
      }
    }
 else     if (changeType == ListEvent.DELETE) {
      Object deleted=barcode.get(changeIndex);
      barcode.remove(changeIndex,1);
      toDoList.remove(changeIndex,1);
      if (deleted == UNIQUE) {
        if (changeIndex < barcode.size() && barcode.get(changeIndex) == DUPLICATE) {
          barcode.set(changeIndex,UNIQUE,1);
          deleted=UNIQUE_WITH_DUPLICATE;
        }
      }
      removedValues.addLast(deleted);
    }
  }
  TryJoinResult<E> tryJoinResult=new TryJoinResult<E>();
  listChanges.reset();
  while (listChanges.next()) {
    final int changeIndex=listChanges.getIndex();
    final int changeType=listChanges.getType();
    E newValue=listChanges.getNewValue();
    E oldValue=listChanges.getOldValue();
    if (changeType == ListEvent.INSERT) {
      tryJoinExistingGroup(changeIndex,toDoList,tryJoinResult);
      if (tryJoinResult.group == NO_GROUP) {
        client.groupChanged(changeIndex,tryJoinResult.groupIndex,ListEvent.INSERT,true,changeType,ListEvent.<E>unknownValue(),tryJoinResult.newFirstInGroup);
      }
 else {
        client.groupChanged(changeIndex,tryJoinResult.groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
      }
    }
 else     if (changeType == ListEvent.UPDATE) {
      int oldGroup=0;
      if (toDoList.get(changeIndex) == TODO) {
        if (changeIndex + 1 < barcode.size()) {
          oldGroup=RIGHT_GROUP;
        }
 else {
          oldGroup=NO_GROUP;
        }
      }
 else       if (barcode.get(changeIndex) == DUPLICATE)       oldGroup=LEFT_GROUP;
 else       if (barcode.get(changeIndex) == UNIQUE)       oldGroup=NO_GROUP;
      tryJoinExistingGroup(changeIndex,toDoList,tryJoinResult);
      int successor=changeIndex + 1;
      if (tryJoinResult.group == LEFT_GROUP) {
        if (successor < barcode.size() && barcode.get(successor) == UNIQUE && toDoList.get(successor) == DONE && groupTogether(changeIndex,successor)) {
          barcode.set(successor,DUPLICATE,1);
          oldGroup=NO_GROUP;
        }
      }
 else       if (tryJoinResult.group == NO_GROUP) {
        if (successor < barcode.size() && barcode.get(successor) == DUPLICATE) {
          barcode.set(successor,UNIQUE,1);
          oldGroup=RIGHT_GROUP;
        }
      }
      int groupIndex=tryJoinResult.groupIndex;
      if (tryJoinResult.group == NO_GROUP) {
        if (oldGroup == NO_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,oldValue,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == LEFT_GROUP) {
          E firstFromPreviousGroup=sortedList.get(barcode.getIndex(groupIndex - 1,UNIQUE));
          client.groupChanged(changeIndex,groupIndex - 1,ListEvent.UPDATE,false,changeType,firstFromPreviousGroup,firstFromPreviousGroup);
          client.groupChanged(changeIndex,groupIndex,ListEvent.INSERT,true,changeType,ListEvent.<E>unknownValue(),tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == RIGHT_GROUP) {
          E firstFromNextGroup=sortedList.get(barcode.getIndex(groupIndex + 1,UNIQUE));
          client.groupChanged(changeIndex,groupIndex,ListEvent.INSERT,true,changeType,ListEvent.<E>unknownValue(),tryJoinResult.newFirstInGroup);
          client.groupChanged(changeIndex,groupIndex + 1,ListEvent.UPDATE,false,changeType,oldValue,firstFromNextGroup);
        }
      }
 else       if (tryJoinResult.group == LEFT_GROUP) {
        if (oldGroup == NO_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
          client.groupChanged(changeIndex,groupIndex + 1,ListEvent.DELETE,false,changeType,oldValue,ListEvent.<E>unknownValue());
        }
 else         if (oldGroup == LEFT_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == RIGHT_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
          if (groupIndex + 1 < barcode.blackSize()) {
            E firstFromNextGroup=sortedList.get(barcode.getIndex(groupIndex + 1,UNIQUE));
            client.groupChanged(changeIndex,groupIndex + 1,ListEvent.UPDATE,false,changeType,oldValue,firstFromNextGroup);
          }
        }
      }
 else       if (tryJoinResult.group == RIGHT_GROUP) {
        if (oldGroup == NO_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.DELETE,false,changeType,oldValue,ListEvent.<E>unknownValue());
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == LEFT_GROUP) {
          if (groupIndex - 1 >= 0) {
            E firstFromPreviousGroup=sortedList.get(barcode.getIndex(groupIndex - 1,UNIQUE));
            client.groupChanged(changeIndex,groupIndex - 1,ListEvent.UPDATE,false,changeType,firstFromPreviousGroup,firstFromPreviousGroup);
          }
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == RIGHT_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
      }
    }
 else     if (changeType == ListEvent.DELETE) {
      final Object deleted=removedValues.removeFirst();
      final int sourceDeletedIndex=deleted == DUPLICATE ? changeIndex - 1 : changeIndex;
      final int groupDeletedIndex=sourceDeletedIndex < barcode.size() ? barcode.getBlackIndex(sourceDeletedIndex,true) : barcode.blackSize();
      if (deleted == UNIQUE) {
        if (changeIndex == lastFakedUniqueChangeIndex) {
        }
 else {
          client.groupChanged(changeIndex,groupDeletedIndex,ListEvent.DELETE,true,changeType,oldValue,ListEvent.<E>unknownValue());
        }
      }
 else {
        E oldValueInGroup;
        E newValueInGroup;
        if (groupDeletedIndex < barcode.blackSize()) {
          int firstInGroupIndex=barcode.getIndex(groupDeletedIndex,UNIQUE);
          newValueInGroup=sortedList.get(firstInGroupIndex);
        }
 else {
          newValueInGroup=ListEvent.<E>unknownValue();
        }
        if (deleted == UNIQUE_WITH_DUPLICATE) {
          oldValueInGroup=oldValue;
        }
 else {
          oldValueInGroup=newValueInGroup;
        }
        client.groupChanged(changeIndex,groupDeletedIndex,ListEvent.UPDATE,true,changeType,oldValueInGroup,newValueInGroup);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Handle changes from the   {@link SortedList} by modifying the grouping state.During this method, callbacks will be made to the  {@link Client} who isresponsible for firing the appropriate change events to its listeners.
 */
public void listChanged(ListEvent<E> listChanges){
  final Barcode toDoList=new Barcode();
  toDoList.addWhite(0,barcode.size());
  final LinkedList removedValues=new LinkedList();
  int lastFakedUniqueChangeIndex=-1;
  while (listChanges.next()) {
    final int changeIndex=listChanges.getIndex();
    final int changeType=listChanges.getType();
    if (changeType == ListEvent.INSERT) {
      barcode.add(changeIndex,UNIQUE,1);
      toDoList.add(changeIndex,TODO,1);
    }
 else     if (changeType == ListEvent.UPDATE) {
      if (barcode.get(changeIndex) == UNIQUE) {
        if (changeIndex + 1 < barcode.size() && barcode.get(changeIndex + 1) == DUPLICATE && (changeIndex == 0 || !uniqueElementAddedToLeftInSameGroup(toDoList,changeIndex))) {
          if (changeIndex != lastFakedUniqueChangeIndex) {
            barcode.set(changeIndex,UNIQUE,2);
            toDoList.set(changeIndex,TODO,1);
            lastFakedUniqueChangeIndex=changeIndex + 1;
          }
        }
      }
    }
 else     if (changeType == ListEvent.DELETE) {
      Object deleted=barcode.get(changeIndex);
      barcode.remove(changeIndex,1);
      toDoList.remove(changeIndex,1);
      if (deleted == UNIQUE) {
        if (changeIndex < barcode.size() && barcode.get(changeIndex) == DUPLICATE) {
          barcode.set(changeIndex,UNIQUE,1);
          deleted=UNIQUE_WITH_DUPLICATE;
        }
      }
      removedValues.addLast(deleted);
    }
  }
  TryJoinResult<E> tryJoinResult=new TryJoinResult<E>();
  listChanges.reset();
  while (listChanges.next()) {
    final int changeIndex=listChanges.getIndex();
    final int changeType=listChanges.getType();
    E newValue=listChanges.getNewValue();
    E oldValue=listChanges.getOldValue();
    if (changeType == ListEvent.INSERT) {
      tryJoinExistingGroup(changeIndex,toDoList,tryJoinResult);
      if (tryJoinResult.group == NO_GROUP) {
        client.groupChanged(changeIndex,tryJoinResult.groupIndex,ListEvent.INSERT,true,changeType,ListEvent.<E>unknownValue(),tryJoinResult.newFirstInGroup);
      }
 else {
        client.groupChanged(changeIndex,tryJoinResult.groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
      }
    }
 else     if (changeType == ListEvent.UPDATE) {
      int oldGroup=0;
      if (toDoList.get(changeIndex) == TODO) {
        if (changeIndex + 1 < barcode.size()) {
          oldGroup=RIGHT_GROUP;
        }
 else {
          oldGroup=NO_GROUP;
        }
      }
 else       if (barcode.get(changeIndex) == DUPLICATE)       oldGroup=LEFT_GROUP;
 else       if (barcode.get(changeIndex) == UNIQUE)       oldGroup=NO_GROUP;
      tryJoinExistingGroup(changeIndex,toDoList,tryJoinResult);
      int successor=changeIndex + 1;
      if (tryJoinResult.group == LEFT_GROUP) {
        if (successor < barcode.size() && barcode.get(successor) == UNIQUE && toDoList.get(successor) == DONE && groupTogether(changeIndex,successor)) {
          barcode.set(successor,DUPLICATE,1);
          oldGroup=NO_GROUP;
        }
      }
 else       if (tryJoinResult.group == NO_GROUP) {
        if (successor < barcode.size() && barcode.get(successor) == DUPLICATE) {
          barcode.set(successor,UNIQUE,1);
          oldGroup=RIGHT_GROUP;
        }
      }
      int groupIndex=tryJoinResult.groupIndex;
      if (tryJoinResult.group == NO_GROUP) {
        if (oldGroup == NO_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,oldValue,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == LEFT_GROUP) {
          E firstFromPreviousGroup=sortedList.get(barcode.getIndex(groupIndex - 1,UNIQUE));
          client.groupChanged(changeIndex,groupIndex - 1,ListEvent.UPDATE,false,changeType,firstFromPreviousGroup,firstFromPreviousGroup);
          client.groupChanged(changeIndex,groupIndex,ListEvent.INSERT,true,changeType,ListEvent.<E>unknownValue(),tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == RIGHT_GROUP) {
          E firstFromNextGroup=sortedList.get(barcode.getIndex(groupIndex + 1,UNIQUE));
          client.groupChanged(changeIndex,groupIndex,ListEvent.INSERT,true,changeType,ListEvent.<E>unknownValue(),tryJoinResult.newFirstInGroup);
          client.groupChanged(changeIndex,groupIndex + 1,ListEvent.UPDATE,false,changeType,oldValue,firstFromNextGroup);
        }
      }
 else       if (tryJoinResult.group == LEFT_GROUP) {
        if (oldGroup == NO_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
          client.groupChanged(changeIndex,groupIndex + 1,ListEvent.DELETE,false,changeType,oldValue,ListEvent.<E>unknownValue());
        }
 else         if (oldGroup == LEFT_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == RIGHT_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
          if (groupIndex + 1 < barcode.blackSize()) {
            E firstFromNextGroup=sortedList.get(barcode.getIndex(groupIndex + 1,UNIQUE));
            client.groupChanged(changeIndex,groupIndex + 1,ListEvent.UPDATE,false,changeType,oldValue,firstFromNextGroup);
          }
        }
      }
 else       if (tryJoinResult.group == RIGHT_GROUP) {
        if (oldGroup == NO_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.DELETE,false,changeType,oldValue,ListEvent.<E>unknownValue());
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == LEFT_GROUP) {
          if (groupIndex - 1 >= 0) {
            E firstFromPreviousGroup=sortedList.get(barcode.getIndex(groupIndex - 1,UNIQUE));
            client.groupChanged(changeIndex,groupIndex - 1,ListEvent.UPDATE,false,changeType,firstFromPreviousGroup,firstFromPreviousGroup);
          }
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
 else         if (oldGroup == RIGHT_GROUP) {
          client.groupChanged(changeIndex,groupIndex,ListEvent.UPDATE,true,changeType,tryJoinResult.oldFirstInGroup,tryJoinResult.newFirstInGroup);
        }
      }
    }
 else     if (changeType == ListEvent.DELETE) {
      final Object deleted=removedValues.removeFirst();
      final int sourceDeletedIndex=deleted == DUPLICATE ? changeIndex - 1 : changeIndex;
      final int groupDeletedIndex=sourceDeletedIndex < barcode.size() ? barcode.getBlackIndex(sourceDeletedIndex,true) : barcode.blackSize();
      if (deleted == UNIQUE) {
        if (changeIndex == lastFakedUniqueChangeIndex) {
        }
 else {
          client.groupChanged(changeIndex,groupDeletedIndex,ListEvent.DELETE,true,changeType,oldValue,ListEvent.<E>unknownValue());
        }
      }
 else {
        E oldValueInGroup;
        E newValueInGroup;
        if (groupDeletedIndex < barcode.blackSize()) {
          int firstInGroupIndex=barcode.getIndex(groupDeletedIndex,UNIQUE);
          newValueInGroup=sortedList.get(firstInGroupIndex);
        }
 else {
          newValueInGroup=ListEvent.<E>unknownValue();
        }
        if (deleted == UNIQUE_WITH_DUPLICATE) {
          oldValueInGroup=oldValue;
        }
 else {
          oldValueInGroup=newValueInGroup;
        }
        client.groupChanged(changeIndex,groupDeletedIndex,ListEvent.UPDATE,true,changeType,oldValueInGroup,newValueInGroup);
      }
    }
  }
}