Program: 38317
Project: 38317
Buggy source:
public Bitmap process(Bitmap originalBitmap,Vector<FilterRepresentation> filters,FilterEnvironment environment){
  Bitmap cacheBitmap=originalBitmap;
  if (filters.size() != mSteps.size()) {
    mSteps.clear();
    for (int i=0; i < filters.size(); i++) {
      FilterRepresentation representation=filters.elementAt(i);
      CacheStep step=new CacheStep();
      step.representation=representation.copy();
      mSteps.add(step);
    }
  }
  if (DEBUG) {
    displayFilters(filters);
  }
  int similarUpToIndex=0;
  for (int i=0; i < filters.size(); i++) {
    FilterRepresentation representation=filters.elementAt(i);
    CacheStep step=mSteps.elementAt(i);
    boolean similar=step.representation.equals(representation);
    if (similar) {
      similarUpToIndex=i;
    }
 else {
      break;
    }
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str" + similarUpToIndex);
  }
  int findBaseImageIndex=similarUpToIndex;
  while (findBaseImageIndex > 0 && mSteps.elementAt(findBaseImageIndex).cache == null) {
    findBaseImageIndex--;
  }
  cacheBitmap=mSteps.elementAt(findBaseImageIndex).cache;
  boolean emptyStack=false;
  if (cacheBitmap == null) {
    emptyStack=true;
    cacheBitmap=originalBitmap.copy(Bitmap.Config.ARGB_8888,true);
    if (DEBUG) {
      Log.v(LOGTAG,"String_Node_Str");
    }
  }
  if (findBaseImageIndex != similarUpToIndex) {
    if (DEBUG) {
      Log.v(LOGTAG,"String_Node_Str" + findBaseImageIndex + "String_Node_Str"+ similarUpToIndex);
    }
    if (!emptyStack) {
      cacheBitmap=cacheBitmap.copy(Bitmap.Config.ARGB_8888,true);
    }
    for (int i=findBaseImageIndex; i <= similarUpToIndex; i++) {
      FilterRepresentation representation=filters.elementAt(i);
      cacheBitmap=environment.applyRepresentation(representation,cacheBitmap);
      if (DEBUG) {
        Log.v(LOGTAG,"String_Node_Str" + i + "String_Node_Str"+ representation.getName());
      }
    }
    mSteps.elementAt(similarUpToIndex).cache=cacheBitmap;
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str" + similarUpToIndex + "String_Node_Str"+ (filters.size() - 1));
  }
  for (int i=similarUpToIndex + 1; i < filters.size(); i++) {
    FilterRepresentation representation=filters.elementAt(i);
    CacheStep currentStep=mSteps.elementAt(i);
    cacheBitmap=cacheBitmap.copy(Bitmap.Config.ARGB_8888,true);
    cacheBitmap=environment.applyRepresentation(representation,cacheBitmap);
    currentStep.representation=representation.copy();
    currentStep.cache=cacheBitmap;
    if (DEBUG) {
      Log.v(LOGTAG,"String_Node_Str" + i + "String_Node_Str"+ representation.getName());
    }
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str");
    displayNbBitmapsInCache();
  }
  for (int i=0; i < similarUpToIndex; i++) {
    CacheStep currentStep=mSteps.elementAt(i);
    currentStep.cache=null;
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str");
    displayNbBitmapsInCache();
  }
  return cacheBitmap;
}

Fixed version (ground truth):
public Bitmap process(Bitmap originalBitmap,Vector<FilterRepresentation> filters,FilterEnvironment environment){
  if (filters.size() == 0) {
    return originalBitmap;
  }
  if (filters.size() != mSteps.size()) {
    mSteps.clear();
    for (int i=0; i < filters.size(); i++) {
      FilterRepresentation representation=filters.elementAt(i);
      CacheStep step=new CacheStep();
      step.representation=representation.copy();
      mSteps.add(step);
    }
  }
  if (DEBUG) {
    displayFilters(filters);
  }
  int similarUpToIndex=-1;
  for (int i=0; i < filters.size(); i++) {
    FilterRepresentation representation=filters.elementAt(i);
    CacheStep step=mSteps.elementAt(i);
    boolean similar=step.representation.equals(representation);
    if (similar) {
      similarUpToIndex=i;
    }
 else {
      break;
    }
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str" + similarUpToIndex);
  }
  Bitmap cacheBitmap=null;
  int findBaseImageIndex=similarUpToIndex;
  if (findBaseImageIndex > -1) {
    while (findBaseImageIndex > 0 && mSteps.elementAt(findBaseImageIndex).cache == null) {
      findBaseImageIndex--;
    }
    cacheBitmap=mSteps.elementAt(findBaseImageIndex).cache;
  }
  boolean emptyStack=false;
  if (cacheBitmap == null) {
    emptyStack=true;
    cacheBitmap=originalBitmap.copy(Bitmap.Config.ARGB_8888,true);
    if (findBaseImageIndex > -1) {
      FilterRepresentation representation=filters.elementAt(findBaseImageIndex);
      cacheBitmap=environment.applyRepresentation(representation,cacheBitmap);
      mSteps.elementAt(findBaseImageIndex).representation=representation.copy();
      mSteps.elementAt(findBaseImageIndex).cache=cacheBitmap;
    }
    if (DEBUG) {
      Log.v(LOGTAG,"String_Node_Str");
    }
  }
  if (findBaseImageIndex != similarUpToIndex) {
    if (DEBUG) {
      Log.v(LOGTAG,"String_Node_Str" + findBaseImageIndex + "String_Node_Str"+ similarUpToIndex);
    }
    if (!emptyStack) {
      cacheBitmap=cacheBitmap.copy(Bitmap.Config.ARGB_8888,true);
    }
 else {
      findBaseImageIndex++;
    }
    for (int i=findBaseImageIndex; i <= similarUpToIndex; i++) {
      FilterRepresentation representation=filters.elementAt(i);
      cacheBitmap=environment.applyRepresentation(representation,cacheBitmap);
      if (DEBUG) {
        Log.v(LOGTAG,"String_Node_Str" + i + "String_Node_Str"+ representation.getName());
      }
    }
    mSteps.elementAt(similarUpToIndex).cache=cacheBitmap;
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str" + similarUpToIndex + "String_Node_Str"+ (filters.size() - 1));
  }
  for (int i=similarUpToIndex + 1; i < filters.size(); i++) {
    FilterRepresentation representation=filters.elementAt(i);
    CacheStep currentStep=mSteps.elementAt(i);
    cacheBitmap=cacheBitmap.copy(Bitmap.Config.ARGB_8888,true);
    cacheBitmap=environment.applyRepresentation(representation,cacheBitmap);
    currentStep.representation=representation.copy();
    currentStep.cache=cacheBitmap;
    if (DEBUG) {
      Log.v(LOGTAG,"String_Node_Str" + i + "String_Node_Str"+ representation.getName());
    }
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str");
    displayNbBitmapsInCache();
  }
  for (int i=0; i < similarUpToIndex; i++) {
    CacheStep currentStep=mSteps.elementAt(i);
    currentStep.cache=null;
  }
  if (DEBUG) {
    Log.v(LOGTAG,"String_Node_Str");
    displayNbBitmapsInCache();
  }
  return cacheBitmap;
}