Program: 56394
Project: 56394
Buggy source:
public void calculatePartitions(){
  for (int y=0; y < height; y++) {
    for (int x=0; x < width; x++) {
      int index=x + y * width;
      if (containing.get(index) ^ invertBitSet) {
        int westX=x + neighborX[0];
        int westY=y + neighborY[0];
        int northWestX=x + neighborX[1];
        int northWestY=y + neighborY[1];
        int northEastX=x + neighborX[2];
        int northEastY=y + neighborY[2];
        int partition=-1;
        int westPartition=-1;
        if (containing.get(westX + westY * width) ^ invertBitSet) {
          westPartition=partitionsGrid[westX + westY * width];
          partition=westPartition;
        }
        if (containing.get(northWestX + northWestY * width) ^ invertBitSet) {
          partition=partitionsGrid[northWestX + northWestY * width];
        }
        int northEastPartition=-1;
        if (containing.get(northEastX + northEastY * width) ^ invertBitSet) {
          northEastPartition=partitionsGrid[northEastX + northEastY * width];
          partition=northEastPartition;
        }
        if (westPartition != -1 && northEastPartition != -1 && partitions[westPartition] != partitions[northEastPartition]) {
          short newPartition=(short)Math.min(partitions[westPartition],partitions[northEastPartition]);
          partitions[westPartition]=newPartition;
          partitions[northEastPartition]=newPartition;
          partitionsGrid[index]=newPartition;
        }
 else         if (partition != -1) {
          partitionsGrid[index]=partitions[partition];
        }
 else {
          partitionsGrid[index]=nextFreePartition;
          partitions[nextFreePartition]=nextFreePartition;
          partitionBorderPositions[nextFreePartition]=new ShortPoint2D(x + minX,y + minY);
          nextFreePartition++;
          if (nextFreePartition >= partitions.length) {
            short[] oldPartitions=partitions;
            partitions=new short[oldPartitions.length * INCREASE_FACTOR];
            System.arraycopy(oldPartitions,0,partitions,0,oldPartitions.length);
            ShortPoint2D[] oldBorderPositions=partitionBorderPositions;
            partitionBorderPositions=new ShortPoint2D[oldBorderPositions.length * INCREASE_FACTOR];
            System.arraycopy(oldBorderPositions,0,partitionBorderPositions,0,oldBorderPositions.length);
          }
        }
      }
    }
  }
  short[] compacted=new short[partitions.length];
  short compactedCount=0;
  for (short i=1; i < nextFreePartition; i++) {
    short representative=i;
    short nextRep;
    while (representative != (nextRep=partitions[representative])) {
      representative=nextRep;
    }
    if (compacted[representative] == 0) {
      compacted[representative]=++compactedCount;
      partitionBorderPositions[compactedCount]=partitionBorderPositions[representative];
    }
    partitions[i]=representative;
    compacted[i]=compacted[representative];
  }
  partitions=compacted;
  neededPartitions=compactedCount;
}

Fixed version (ground truth):
/** 
 * Calculates the partitions. <br> The results can be accessed with the supplied getter methods.
 */
public void calculatePartitions(){
  for (int y=0; y < height; y++) {
    for (int x=0; x < width; x++) {
      int index=x + y * width;
      if (containing.get(index) ^ invertBitSet) {
        int westX=x + neighborX[0];
        int westY=y + neighborY[0];
        int northWestX=x + neighborX[1];
        int northWestY=y + neighborY[1];
        int northEastX=x + neighborX[2];
        int northEastY=y + neighborY[2];
        int partition=-1;
        int westPartition=-1;
        if (containing.get(westX + westY * width) ^ invertBitSet) {
          westPartition=partitionsGrid[westX + westY * width];
          partition=westPartition;
        }
        if (containing.get(northWestX + northWestY * width) ^ invertBitSet) {
          partition=partitionsGrid[northWestX + northWestY * width];
        }
        int northEastPartition=-1;
        if (containing.get(northEastX + northEastY * width) ^ invertBitSet) {
          northEastPartition=partitionsGrid[northEastX + northEastY * width];
          partition=northEastPartition;
        }
        if (westPartition != -1 && northEastPartition != -1 && partitions[westPartition] != partitions[northEastPartition]) {
          short newPartition=(short)Math.min(partitions[westPartition],partitions[northEastPartition]);
          partitions[westPartition]=newPartition;
          partitions[northEastPartition]=newPartition;
          partitionsGrid[index]=newPartition;
        }
 else         if (partition != -1) {
          partitionsGrid[index]=partitions[partition];
        }
 else {
          partitionsGrid[index]=nextFreePartition;
          partitions[nextFreePartition]=nextFreePartition;
          partitionBorderPositions[nextFreePartition]=new ShortPoint2D(x + minX,y + minY);
          nextFreePartition++;
          if (nextFreePartition >= partitions.length) {
            short[] oldPartitions=partitions;
            partitions=new short[oldPartitions.length * INCREASE_FACTOR];
            System.arraycopy(oldPartitions,0,partitions,0,oldPartitions.length);
            ShortPoint2D[] oldBorderPositions=partitionBorderPositions;
            partitionBorderPositions=new ShortPoint2D[oldBorderPositions.length * INCREASE_FACTOR];
            System.arraycopy(oldBorderPositions,0,partitionBorderPositions,0,oldBorderPositions.length);
          }
        }
      }
    }
  }
  short[] compacted=new short[partitions.length];
  short compactedCount=0;
  for (short i=1; i < nextFreePartition; i++) {
    short representative=i;
    short nextRep;
    while (representative != (nextRep=partitions[representative])) {
      representative=nextRep;
    }
    if (compacted[representative] == 0) {
      compacted[representative]=++compactedCount;
      partitionBorderPositions[compactedCount]=partitionBorderPositions[representative];
    }
    partitions[i]=representative;
    compacted[i]=compacted[representative];
  }
  partitions=compacted;
  neededPartitions=compactedCount;
}