Program: 85231
Project: 85231
Buggy source:
/** 
 * Transforms the given class, i.e. scans for a <clinit> method and generates new constant value tags for all constant assignments to static final fields.
 * @param sc The class to transform
 * @param removeAssignments True if the assignments inside the <clinit> method shall be removed, otherwise false
 */
public void transformClass(SootClass sc,boolean removeAssignments){
  SootMethod smInit=sc.getMethodByNameUnsafe("String_Node_Str");
  if (smInit == null)   return;
  Set<SootField> nonConstantFields=new HashSet<SootField>();
  Map<SootField,ConstantValueTag> newTags=new HashMap<SootField,ConstantValueTag>();
  Set<SootField> removeTagList=new HashSet<SootField>();
  for (Iterator<Unit> itU=smInit.getActiveBody().getUnits().snapshotIterator(); itU.hasNext(); ) {
    Unit u=itU.next();
    if (u instanceof AssignStmt) {
      AssignStmt assign=(AssignStmt)u;
      if (assign.getLeftOp() instanceof StaticFieldRef && assign.getRightOp() instanceof Constant) {
        SootField field=null;
        try {
          field=((StaticFieldRef)assign.getLeftOp()).getField();
          if (field == null || nonConstantFields.contains(field))           continue;
        }
 catch (        ConflictingFieldRefException ex) {
          continue;
        }
        if (field.getDeclaringClass().equals(sc) && field.isStatic() && field.isFinal()) {
          boolean found=false;
          for (          Tag t : field.getTags()) {
            if (t instanceof ConstantValueTag) {
              if (checkConstantValue((ConstantValueTag)t,(Constant)assign.getRightOp())) {
                if (removeAssignments)                 itU.remove();
              }
 else {
                G.v().out.println("String_Node_Str" + field + "String_Node_Str"+ assign.getRightOp()+ "String_Node_Str"+ t+ "String_Node_Str");
                removeTagList.add(field);
              }
              found=true;
              break;
            }
          }
          if (!found) {
            if (!checkConstantValue(newTags.get(field),(Constant)assign.getRightOp())) {
              nonConstantFields.add(field);
              newTags.remove(field);
              removeTagList.add(field);
              continue;
            }
            ConstantValueTag newTag=createConstantTagFromValue((Constant)assign.getRightOp());
            if (newTag != null)             newTags.put(field,newTag);
          }
        }
      }
 else       if (assign.getLeftOp() instanceof StaticFieldRef) {
        try {
          SootField sf=((StaticFieldRef)assign.getLeftOp()).getField();
          if (sf != null)           removeTagList.add(sf);
        }
 catch (        ConflictingFieldRefException ex) {
        }
      }
    }
  }
  for (  Entry<SootField,ConstantValueTag> entry : newTags.entrySet()) {
    SootField field=entry.getKey();
    if (removeTagList.contains(field))     continue;
    field.addTag(entry.getValue());
  }
  if (removeAssignments && !newTags.isEmpty())   for (Iterator<Unit> itU=smInit.getActiveBody().getUnits().snapshotIterator(); itU.hasNext(); ) {
    Unit u=itU.next();
    if (u instanceof AssignStmt) {
      AssignStmt assign=(AssignStmt)u;
      if (assign.getLeftOp() instanceof FieldRef)       try {
        SootField fld=((FieldRef)assign.getLeftOp()).getField();
        if (fld != null && newTags.containsKey(fld))         itU.remove();
      }
 catch (      ConflictingFieldRefException ex) {
      }
    }
  }
  for (  SootField sf : removeTagList) {
    if (removeTagList.contains(sf)) {
      List<Tag> toRemoveTagList=new ArrayList<Tag>();
      for (      Tag t : sf.getTags()) {
        if (t instanceof ConstantValueTag) {
          toRemoveTagList.add(t);
        }
      }
      for (      Tag t : toRemoveTagList) {
        sf.getTags().remove(t);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Transforms the given class, i.e. scans for a <clinit> method and generates new constant value tags for all constant assignments to static final fields.
 * @param sc The class to transform
 * @param removeAssignments True if the assignments inside the <clinit> method shall be removed, otherwise false
 */
public void transformClass(SootClass sc,boolean removeAssignments){
  SootMethod smInit=sc.getMethodByNameUnsafe("String_Node_Str");
  if (smInit == null || !smInit.isConcrete())   return;
  Set<SootField> nonConstantFields=new HashSet<SootField>();
  Map<SootField,ConstantValueTag> newTags=new HashMap<SootField,ConstantValueTag>();
  Set<SootField> removeTagList=new HashSet<SootField>();
  for (Iterator<Unit> itU=smInit.getActiveBody().getUnits().snapshotIterator(); itU.hasNext(); ) {
    Unit u=itU.next();
    if (u instanceof AssignStmt) {
      AssignStmt assign=(AssignStmt)u;
      if (assign.getLeftOp() instanceof StaticFieldRef && assign.getRightOp() instanceof Constant) {
        SootField field=null;
        try {
          field=((StaticFieldRef)assign.getLeftOp()).getField();
          if (field == null || nonConstantFields.contains(field))           continue;
        }
 catch (        ConflictingFieldRefException ex) {
          continue;
        }
        if (field.getDeclaringClass().equals(sc) && field.isStatic() && field.isFinal()) {
          boolean found=false;
          for (          Tag t : field.getTags()) {
            if (t instanceof ConstantValueTag) {
              if (checkConstantValue((ConstantValueTag)t,(Constant)assign.getRightOp())) {
                if (removeAssignments)                 itU.remove();
              }
 else {
                G.v().out.println("String_Node_Str" + field + "String_Node_Str"+ assign.getRightOp()+ "String_Node_Str"+ t+ "String_Node_Str");
                removeTagList.add(field);
              }
              found=true;
              break;
            }
          }
          if (!found) {
            if (!checkConstantValue(newTags.get(field),(Constant)assign.getRightOp())) {
              nonConstantFields.add(field);
              newTags.remove(field);
              removeTagList.add(field);
              continue;
            }
            ConstantValueTag newTag=createConstantTagFromValue((Constant)assign.getRightOp());
            if (newTag != null)             newTags.put(field,newTag);
          }
        }
      }
 else       if (assign.getLeftOp() instanceof StaticFieldRef) {
        try {
          SootField sf=((StaticFieldRef)assign.getLeftOp()).getField();
          if (sf != null)           removeTagList.add(sf);
        }
 catch (        ConflictingFieldRefException ex) {
        }
      }
    }
  }
  for (  Entry<SootField,ConstantValueTag> entry : newTags.entrySet()) {
    SootField field=entry.getKey();
    if (removeTagList.contains(field))     continue;
    field.addTag(entry.getValue());
  }
  if (removeAssignments && !newTags.isEmpty())   for (Iterator<Unit> itU=smInit.getActiveBody().getUnits().snapshotIterator(); itU.hasNext(); ) {
    Unit u=itU.next();
    if (u instanceof AssignStmt) {
      AssignStmt assign=(AssignStmt)u;
      if (assign.getLeftOp() instanceof FieldRef)       try {
        SootField fld=((FieldRef)assign.getLeftOp()).getField();
        if (fld != null && newTags.containsKey(fld))         itU.remove();
      }
 catch (      ConflictingFieldRefException ex) {
      }
    }
  }
  for (  SootField sf : removeTagList) {
    if (removeTagList.contains(sf)) {
      List<Tag> toRemoveTagList=new ArrayList<Tag>();
      for (      Tag t : sf.getTags()) {
        if (t instanceof ConstantValueTag) {
          toRemoveTagList.add(t);
        }
      }
      for (      Tag t : toRemoveTagList) {
        sf.getTags().remove(t);
      }
    }
  }
}