Program: 74496
Project: 74496
Buggy source:
public void replaceTokenFields(SootClass entityClass,int depth,Set unsafeLocalSet,boolean debug){
  boolean doneSomething=false;
  if (debug) {
    System.err.println("String_Node_Str" + entityClass + "String_Node_Str"+ depth);
    System.out.println("String_Node_Str" + entityClass + "String_Node_Str"+ depth);
  }
  TypeSpecializerAnalysis typeAnalysis=new TypeSpecializerAnalysis(entityClass,unsafeLocalSet);
  for (Iterator methods=entityClass.getMethods().iterator(); methods.hasNext(); ) {
    SootMethod method=(SootMethod)methods.next();
    if (_methodWillBeInlined(method)) {
      continue;
    }
    JimpleBody body=(JimpleBody)method.retrieveActiveBody();
    if (debug) {
      System.out.println("String_Node_Str" + method);
    }
    for (Iterator locals=body.getLocals().snapshotIterator(); locals.hasNext(); ) {
      Local local=(Local)locals.next();
      Type localType=typeAnalysis.getSpecializedSootType(local);
      if (debug) {
        System.out.println("String_Node_Str" + local);
      }
      if (debug) {
        System.out.println("String_Node_Str" + localType);
      }
      if (!PtolemyUtilities.isConcreteTokenType(localType) || unsafeLocalSet.contains(local)) {
        if (debug) {
          System.out.println("String_Node_Str");
        }
        continue;
      }
      ptolemy.data.type.Type localTokenType=typeAnalysis.getSpecializedType(local);
      if (debug) {
        System.out.println("String_Node_Str" + localTokenType);
      }
      if (PtolemyUtilities.getTypeDepth(localTokenType) != depth) {
        if (debug) {
          System.out.println("String_Node_Str" + PtolemyUtilities.getTypeDepth(localTokenType));
        }
        continue;
      }
      if (localToFieldToLocal.get(local) != null) {
        continue;
      }
      RefType type=PtolemyUtilities.getBaseTokenType(localType);
      SootClass localClass=type.getSootClass();
      if (!SootUtilities.derivesFrom(localClass,PtolemyUtilities.tokenClass)) {
        if (debug) {
          System.out.println("String_Node_Str");
        }
        continue;
      }
      if (debug) {
        System.out.println("String_Node_Str" + local);
      }
      if (debug) {
        System.out.println("String_Node_Str" + localClass);
      }
      doneSomething=true;
      Type isNotNullType=SootUtilities.createIsomorphicType(localType,BooleanType.v());
      Local isNotNullLocal=Jimple.v().newLocal(local.getName() + "String_Node_Str",isNotNullType);
      body.getLocals().add(isNotNullLocal);
      localToIsNotNullLocal.put(local,isNotNullLocal);
      Map tokenFieldToReplacementLocal=new HashMap();
      localToFieldToLocal.put(local,tokenFieldToReplacementLocal);
      for (Iterator tokenFields=_getTokenClassFields(localClass).iterator(); tokenFields.hasNext(); ) {
        SootField tokenField=(SootField)tokenFields.next();
        if (debug) {
          System.out.println("String_Node_Str" + tokenField);
        }
        Type replacementType=SootUtilities.createIsomorphicType(localType,tokenField.getType());
        Local replacementLocal=Jimple.v().newLocal(local.getName() + "String_Node_Str" + tokenField.getName(),replacementType);
        body.getLocals().add(replacementLocal);
        tokenFieldToReplacementLocal.put(tokenField,replacementLocal);
      }
    }
    for (Iterator units=body.getUnits().snapshotIterator(); units.hasNext(); ) {
      Unit unit=(Unit)units.next();
      if (debug) {
        System.out.println("String_Node_Str" + unit);
      }
      if (unit instanceof InvokeStmt) {
        InvokeExpr r=(InvokeExpr)((InvokeStmt)unit).getInvokeExpr();
        if (r.getMethod().equals(PtolemyUtilities.arraycopyMethod)) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          Local toLocal=(Local)r.getArg(0);
          Local fromLocal=(Local)r.getArg(2);
          Map toFieldToReplacementLocal=(Map)localToFieldToLocal.get(toLocal);
          Map fromFieldToReplacementLocal=(Map)localToFieldToLocal.get(fromLocal);
          if ((toFieldToReplacementLocal != null) && (fromFieldToReplacementLocal != null)) {
            if (debug) {
              System.out.println("String_Node_Str" + toFieldToReplacementLocal);
            }
            if (debug) {
              System.out.println("String_Node_Str" + fromFieldToReplacementLocal);
            }
{
              List argumentList=new LinkedList();
              argumentList.add((Local)localToIsNotNullLocal.get(toLocal));
              argumentList.add(r.getArg(1));
              argumentList.add((Local)localToIsNotNullLocal.get(fromLocal));
              argumentList.add(r.getArg(3));
              argumentList.add(r.getArg(4));
              body.getUnits().insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(PtolemyUtilities.arraycopyMethod.makeRef(),argumentList)),unit);
            }
            for (Iterator tokenFields=toFieldToReplacementLocal.entrySet().iterator(); tokenFields.hasNext(); ) {
              Map.Entry entry=(Map.Entry)tokenFields.next();
              SootField tokenField=(SootField)entry.getKey();
              Local toReplacementLocal=(Local)entry.getValue();
              Local fromReplacementLocal=(Local)fromFieldToReplacementLocal.get(tokenField);
              List argumentList=new LinkedList();
              argumentList.add(toReplacementLocal);
              argumentList.add(r.getArg(1));
              argumentList.add(fromReplacementLocal);
              argumentList.add(r.getArg(3));
              argumentList.add(r.getArg(4));
              body.getUnits().insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(PtolemyUtilities.arraycopyMethod.makeRef(),argumentList)),unit);
            }
            body.getUnits().remove(unit);
            doneSomething=true;
          }
        }
      }
 else       if (unit instanceof AssignStmt) {
        AssignStmt stmt=(AssignStmt)unit;
        stmt.getLeftOp().getType();
        if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof LengthExpr) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          LengthExpr lengthExpr=(LengthExpr)stmt.getRightOp();
          Local baseLocal=(Local)lengthExpr.getOp();
          if (debug) {
            System.out.println("String_Node_Str" + baseLocal);
          }
          Map fieldToReplacementArrayLocal=(Map)localToFieldToLocal.get(baseLocal);
          if (fieldToReplacementArrayLocal != null) {
            doneSomething=true;
            List replacementList=new ArrayList(fieldToReplacementArrayLocal.keySet());
            Collections.sort(replacementList,new Comparator(){
              public int compare(              Object o1,              Object o2){
                SootField f1=(SootField)o1;
                SootField f2=(SootField)o2;
                return f1.getName().compareTo(f2.getName());
              }
            }
);
            SootField field=(SootField)replacementList.get(replacementList.size() - 1);
            if (debug) {
              System.out.println("String_Node_Str" + fieldToReplacementArrayLocal.get(field));
            }
            lengthExpr.setOp((Local)fieldToReplacementArrayLocal.get(field));
            if (debug) {
              System.out.println("String_Node_Str" + unit);
            }
          }
        }
 else         if (stmt.getLeftOp() instanceof InstanceFieldRef) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          InstanceFieldRef r=(InstanceFieldRef)stmt.getLeftOp();
          SootField field=r.getField();
          if (r.getBase().getType() instanceof RefType) {
            RefType type=(RefType)r.getBase().getType();
            if (SootUtilities.derivesFrom(type.getSootClass(),PtolemyUtilities.tokenClass)) {
              if (debug) {
                System.out.println("String_Node_Str" + unit + "String_Node_Str");
              }
              Local baseLocal=(Local)r.getBase();
              Local instanceLocal=_getInstanceLocal(body,baseLocal,field,localToFieldToLocal,debug);
              if (debug) {
                System.out.println("String_Node_Str" + instanceLocal);
              }
              if (instanceLocal != null) {
                stmt.getLeftOpBox().setValue(instanceLocal);
                doneSomething=true;
              }
            }
          }
        }
 else         if (stmt.getRightOp() instanceof InstanceFieldRef) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          InstanceFieldRef r=(InstanceFieldRef)stmt.getRightOp();
          SootField field=r.getField();
          if (r.getBase().getType() instanceof RefType) {
            RefType type=(RefType)r.getBase().getType();
            if (SootUtilities.derivesFrom(type.getSootClass(),PtolemyUtilities.tokenClass)) {
              if (debug) {
                System.out.println("String_Node_Str" + unit + "String_Node_Str");
              }
              Local baseLocal=(Local)r.getBase();
              Local instanceLocal=_getInstanceLocal(body,baseLocal,field,localToFieldToLocal,debug);
              if (debug) {
                System.out.println("String_Node_Str" + instanceLocal);
              }
              if (instanceLocal != null) {
                stmt.getRightOpBox().setValue(instanceLocal);
                doneSomething=true;
              }
            }
          }
        }
      }
    }
  }
  if (debug) {
    System.out.println("String_Node_Str" + entityClass);
  }
  for (Iterator methods=entityClass.getMethods().iterator(); methods.hasNext(); ) {
    SootMethod method=(SootMethod)methods.next();
    if (debug) {
      System.out.println("String_Node_Str" + method);
    }
    JimpleBody body=(JimpleBody)method.retrieveActiveBody();
    for (Iterator units=body.getUnits().snapshotIterator(); units.hasNext(); ) {
      Unit unit=(Unit)units.next();
      if (debug) {
        System.out.println("String_Node_Str" + unit);
      }
      if (unit instanceof AssignStmt) {
        AssignStmt stmt=(AssignStmt)unit;
        Type assignmentType=stmt.getLeftOp().getType();
        if (PtolemyUtilities.isTokenType(assignmentType)) {
          if (stmt.getLeftOp() instanceof Local && (stmt.getRightOp() instanceof Local || stmt.getRightOp() instanceof Constant)) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            doneSomething|=_handleImmediateAssignment(body,stmt,localToFieldToLocal,localToIsNotNullLocal,stmt.getLeftOp(),stmt.getRightOp(),debug);
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof CastExpr) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            Value rightLocal=((CastExpr)stmt.getRightOp()).getOp();
            doneSomething|=_handleImmediateAssignment(body,stmt,localToFieldToLocal,localToIsNotNullLocal,stmt.getLeftOp(),rightLocal,debug);
          }
 else           if (stmt.getLeftOp() instanceof FieldRef && stmt.getRightOp() instanceof Local) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            FieldRef oldFieldRef=(FieldRef)stmt.getLeftOp();
            SootField field=oldFieldRef.getField();
            Map fieldToReplacementField=(Map)entityFieldToTokenFieldToReplacementField.get(field);
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getRightOp());
            if ((fieldToReplacementLocal != null) && (fieldToReplacementField != null)) {
              doneSomething=true;
{
                SootField replacementField=(SootField)entityFieldToIsNotNullField.get(field);
                FieldRef isNotNullFieldRef;
                if (oldFieldRef instanceof InstanceFieldRef) {
                  isNotNullFieldRef=Jimple.v().newInstanceFieldRef(((InstanceFieldRef)oldFieldRef).getBase(),replacementField.makeRef());
                }
 else {
                  isNotNullFieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(isNotNullFieldRef,(Local)localToIsNotNullLocal.get(stmt.getRightOp())),unit);
              }
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementField.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                SootField replacementField=(SootField)fieldToReplacementField.get(tokenField);
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + replacementLocal);
                }
                FieldRef fieldRef;
                if (stmt.getLeftOp() instanceof InstanceFieldRef) {
                  Local base=(Local)((InstanceFieldRef)stmt.getLeftOp()).getBase();
                  fieldRef=Jimple.v().newInstanceFieldRef(base,replacementField.makeRef());
                }
 else {
                  fieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(fieldRef,replacementLocal),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof FieldRef) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            FieldRef oldFieldRef=(FieldRef)stmt.getRightOp();
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            SootField field=oldFieldRef.getField();
            Map fieldToReplacementField=(Map)entityFieldToTokenFieldToReplacementField.get(field);
            boolean isSingleton=false;
            if (field.getName().equals("String_Node_Str") || field.getName().equals("String_Node_Str") || field.getName().equals("String_Node_Str")|| field.getName().equals("String_Node_Str")) {
              isSingleton=true;
            }
            if ((isSingleton) && (fieldToReplacementLocal != null)) {
              doneSomething=true;
              body.getUnits().insertBefore(Jimple.v().newAssignStmt((Local)localToIsNotNullLocal.get(stmt.getLeftOp()),IntConstant.v(1)),unit);
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator localFields=fieldToReplacementLocal.entrySet().iterator(); localFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)localFields.next();
                SootField localField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + localField);
                }
                if (localField.getName().equals("String_Node_Str")) {
                  Local replacementLocal=(Local)entry.getValue();
                  body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,NullConstant.v()),unit);
                }
 else                 if (localField.getName().equals("String_Node_Str")) {
                  Local replacementLocal=(Local)fieldToReplacementLocal.get(localField);
                  if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,LongConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,LongConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,DoubleConstant.v(1.0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,DoubleConstant.v(0.0)),unit);
                  }
                }
 else {
                  throw new RuntimeException("String_Node_Str" + localField.getSignature());
                }
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
 else             if ((fieldToReplacementLocal != null) && (fieldToReplacementField != null)) {
              doneSomething=true;
{
                SootField replacementField=(SootField)entityFieldToIsNotNullField.get(field);
                FieldRef isNotNullFieldRef;
                if (oldFieldRef instanceof InstanceFieldRef) {
                  isNotNullFieldRef=Jimple.v().newInstanceFieldRef(((InstanceFieldRef)oldFieldRef).getBase(),replacementField.makeRef());
                }
 else {
                  isNotNullFieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt((Local)localToIsNotNullLocal.get(stmt.getLeftOp()),isNotNullFieldRef),unit);
              }
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementField.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                SootField replacementField=(SootField)fieldToReplacementField.get(tokenField);
                Local replacementLocal=(Local)entry.getValue();
                FieldRef fieldRef;
                if (stmt.getRightOp() instanceof InstanceFieldRef) {
                  Local base=(Local)((InstanceFieldRef)stmt.getRightOp()).getBase();
                  fieldRef=Jimple.v().newInstanceFieldRef(base,replacementField.makeRef());
                }
 else {
                  fieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                if (debug) {
                  System.out.println("String_Node_Str" + replacementLocal);
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,fieldRef),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof ArrayRef && stmt.getRightOp() instanceof Local) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            ArrayRef arrayRef=(ArrayRef)stmt.getLeftOp();
            Local baseLocal=(Local)arrayRef.getBase();
            Map fieldToReplacementArrayLocal=(Map)localToFieldToLocal.get(baseLocal);
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getRightOp());
            if (debug) {
              System.out.println("String_Node_Str" + fieldToReplacementArrayLocal);
            }
            if (debug) {
              System.out.println("String_Node_Str" + fieldToReplacementLocal);
            }
            if ((fieldToReplacementLocal != null) && (fieldToReplacementArrayLocal != null)) {
              doneSomething=true;
              body.getUnits().insertBefore(Jimple.v().newAssignStmt(Jimple.v().newArrayRef((Local)localToIsNotNullLocal.get(baseLocal),arrayRef.getIndex()),(Local)localToIsNotNullLocal.get(stmt.getRightOp())),unit);
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementLocal.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Local replacementArrayLocal=(Local)fieldToReplacementArrayLocal.get(tokenField);
                Local replacementLocal=(Local)entry.getValue();
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(Jimple.v().newArrayRef(replacementArrayLocal,arrayRef.getIndex()),replacementLocal),unit);
              }
              body.getUnits().remove(unit);
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof ArrayRef) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            ArrayRef arrayRef=(ArrayRef)stmt.getRightOp();
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            Local baseLocal=(Local)arrayRef.getBase();
            Map fieldToReplacementArrayLocal=(Map)localToFieldToLocal.get(baseLocal);
            if ((fieldToReplacementLocal != null) && (fieldToReplacementArrayLocal != null)) {
              doneSomething=true;
              body.getUnits().insertBefore(Jimple.v().newAssignStmt((Local)localToIsNotNullLocal.get(stmt.getLeftOp()),Jimple.v().newArrayRef((Local)localToIsNotNullLocal.get(baseLocal),arrayRef.getIndex())),unit);
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementLocal.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Local replacementArrayLocal=(Local)fieldToReplacementArrayLocal.get(tokenField);
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + replacementLocal);
                }
                if (debug) {
                  System.out.println("String_Node_Str" + replacementArrayLocal);
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,Jimple.v().newArrayRef(replacementArrayLocal,arrayRef.getIndex())),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof NewArrayExpr) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            NewArrayExpr newExpr=(NewArrayExpr)stmt.getRightOp();
            Map map=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            if (map != null) {
              doneSomething=true;
              Type isNotNullType=SootUtilities.createIsomorphicType(newExpr.getBaseType(),BooleanType.v());
              Local isNotNullLocal=(Local)localToIsNotNullLocal.get(stmt.getLeftOp());
              body.getUnits().insertBefore(Jimple.v().newAssignStmt(isNotNullLocal,Jimple.v().newNewArrayExpr(isNotNullType,newExpr.getSize())),unit);
              for (Iterator tokenFields=map.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Type replacementType=SootUtilities.createIsomorphicType(newExpr.getBaseType(),tokenField.getType());
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,Jimple.v().newNewArrayExpr(replacementType,newExpr.getSize())),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof NewExpr) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            stmt.getRightOp();
            Map map=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            if (map != null) {
              doneSomething=true;
              Local isNotNullLocal=(Local)localToIsNotNullLocal.get(stmt.getLeftOp());
              if (debug) {
                System.out.println("String_Node_Str" + stmt);
              }
              body.getUnits().insertBefore(Jimple.v().newAssignStmt(isNotNullLocal,IntConstant.v(1)),unit);
              for (Iterator tokenFields=map.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Value replacementValue=_getNullValueForType(replacementLocal.getType());
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,replacementValue),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
        }
      }
      for (Iterator boxes=unit.getUseAndDefBoxes().iterator(); boxes.hasNext(); ) {
        ValueBox box=(ValueBox)boxes.next();
        Value value=box.getValue();
        if (value instanceof BinopExpr) {
          BinopExpr expr=(BinopExpr)value;
          boolean op1IsToken=PtolemyUtilities.isTokenType(expr.getOp1().getType());
          boolean op2IsToken=PtolemyUtilities.isTokenType(expr.getOp2().getType());
          if (op1IsToken && op2IsToken) {
          }
 else           if (op1IsToken && expr.getOp2().getType().equals(NullType.v())) {
            doneSomething=true;
            Local isNotNullLocal=(Local)localToIsNotNullLocal.get(expr.getOp1());
            if (isNotNullLocal != null) {
              if (debug) {
                System.out.println("String_Node_Str" + expr);
              }
              Value nullValue;
              if (isNotNullLocal.getType().equals(BooleanType.v())) {
                nullValue=IntConstant.v(0);
              }
 else {
                nullValue=NullConstant.v();
              }
              if (expr instanceof EqExpr) {
                box.setValue(Jimple.v().newEqExpr(isNotNullLocal,nullValue));
              }
 else               if (expr instanceof NeExpr) {
                box.setValue(Jimple.v().newNeExpr(isNotNullLocal,nullValue));
              }
            }
          }
 else           if (op2IsToken && expr.getOp1().getType().equals(NullType.v())) {
            doneSomething=true;
            Local isNotNullLocal=(Local)localToIsNotNullLocal.get(expr.getOp2());
            if (isNotNullLocal != null) {
              Value nullValue;
              if (isNotNullLocal.getType().equals(BooleanType.v())) {
                nullValue=IntConstant.v(0);
              }
 else {
                nullValue=NullConstant.v();
              }
              if (expr instanceof EqExpr) {
                box.setValue(Jimple.v().newEqExpr(isNotNullLocal,nullValue));
              }
 else               if (expr instanceof NeExpr) {
                box.setValue(Jimple.v().newNeExpr(isNotNullLocal,nullValue));
              }
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
public void replaceTokenFields(SootClass entityClass,int depth,Set unsafeLocalSet,boolean debug){
  boolean doneSomething=false;
  if (debug) {
    System.err.println("String_Node_Str" + entityClass + "String_Node_Str"+ depth);
    System.out.println("String_Node_Str" + entityClass + "String_Node_Str"+ depth);
  }
  TypeSpecializerAnalysis typeAnalysis=new TypeSpecializerAnalysis(entityClass,unsafeLocalSet);
  for (Iterator methods=entityClass.getMethods().iterator(); methods.hasNext(); ) {
    SootMethod method=(SootMethod)methods.next();
    if (_methodWillBeInlined(method)) {
      continue;
    }
    JimpleBody body=(JimpleBody)method.retrieveActiveBody();
    if (debug) {
      System.out.println("String_Node_Str" + method);
    }
    for (Iterator locals=body.getLocals().snapshotIterator(); locals.hasNext(); ) {
      Local local=(Local)locals.next();
      Type localType=typeAnalysis.getSpecializedSootType(local);
      if (debug) {
        System.out.println("String_Node_Str" + local);
      }
      if (debug) {
        System.out.println("String_Node_Str" + localType);
      }
      if (!PtolemyUtilities.isConcreteTokenType(localType) || unsafeLocalSet.contains(local)) {
        if (debug) {
          System.out.println("String_Node_Str");
        }
        continue;
      }
      ptolemy.data.type.Type localTokenType=typeAnalysis.getSpecializedType(local);
      if (debug) {
        System.out.println("String_Node_Str" + localTokenType);
      }
      if (PtolemyUtilities.getTypeDepth(localTokenType) != depth) {
        if (debug) {
          System.out.println("String_Node_Str" + PtolemyUtilities.getTypeDepth(localTokenType));
        }
        continue;
      }
      if (localToFieldToLocal.get(local) != null) {
        continue;
      }
      RefType type=PtolemyUtilities.getBaseTokenType(localType);
      SootClass localClass=type.getSootClass();
      if (!SootUtilities.derivesFrom(localClass,PtolemyUtilities.tokenClass)) {
        if (debug) {
          System.out.println("String_Node_Str");
        }
        continue;
      }
      if (debug) {
        System.out.println("String_Node_Str" + local);
      }
      if (debug) {
        System.out.println("String_Node_Str" + localClass);
      }
      doneSomething=true;
      Type isNotNullType=SootUtilities.createIsomorphicType(localType,BooleanType.v());
      Local isNotNullLocal=Jimple.v().newLocal(local.getName() + "String_Node_Str",isNotNullType);
      body.getLocals().add(isNotNullLocal);
      localToIsNotNullLocal.put(local,isNotNullLocal);
      Map tokenFieldToReplacementLocal=new HashMap();
      localToFieldToLocal.put(local,tokenFieldToReplacementLocal);
      for (Iterator tokenFields=_getTokenClassFields(localClass).iterator(); tokenFields.hasNext(); ) {
        SootField tokenField=(SootField)tokenFields.next();
        if (debug) {
          System.out.println("String_Node_Str" + tokenField);
        }
        Type replacementType=SootUtilities.createIsomorphicType(localType,tokenField.getType());
        Local replacementLocal=Jimple.v().newLocal(local.getName() + "String_Node_Str" + tokenField.getName(),replacementType);
        body.getLocals().add(replacementLocal);
        tokenFieldToReplacementLocal.put(tokenField,replacementLocal);
      }
    }
    for (Iterator units=body.getUnits().snapshotIterator(); units.hasNext(); ) {
      Unit unit=(Unit)units.next();
      if (debug) {
        System.out.println("String_Node_Str" + unit);
      }
      if (unit instanceof InvokeStmt) {
        InvokeExpr r=(InvokeExpr)((InvokeStmt)unit).getInvokeExpr();
        if (r.getMethod().equals(PtolemyUtilities.arraycopyMethod)) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          Local toLocal=(Local)r.getArg(0);
          Local fromLocal=(Local)r.getArg(2);
          Map toFieldToReplacementLocal=(Map)localToFieldToLocal.get(toLocal);
          Map fromFieldToReplacementLocal=(Map)localToFieldToLocal.get(fromLocal);
          if ((toFieldToReplacementLocal != null) && (fromFieldToReplacementLocal != null)) {
            if (debug) {
              System.out.println("String_Node_Str" + toFieldToReplacementLocal);
            }
            if (debug) {
              System.out.println("String_Node_Str" + fromFieldToReplacementLocal);
            }
{
              List argumentList=new LinkedList();
              argumentList.add((Local)localToIsNotNullLocal.get(toLocal));
              argumentList.add(r.getArg(1));
              argumentList.add((Local)localToIsNotNullLocal.get(fromLocal));
              argumentList.add(r.getArg(3));
              argumentList.add(r.getArg(4));
              body.getUnits().insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(PtolemyUtilities.arraycopyMethod.makeRef(),argumentList)),unit);
            }
            for (Iterator tokenFields=toFieldToReplacementLocal.entrySet().iterator(); tokenFields.hasNext(); ) {
              Map.Entry entry=(Map.Entry)tokenFields.next();
              SootField tokenField=(SootField)entry.getKey();
              Local toReplacementLocal=(Local)entry.getValue();
              Local fromReplacementLocal=(Local)fromFieldToReplacementLocal.get(tokenField);
              List argumentList=new LinkedList();
              argumentList.add(toReplacementLocal);
              argumentList.add(r.getArg(1));
              argumentList.add(fromReplacementLocal);
              argumentList.add(r.getArg(3));
              argumentList.add(r.getArg(4));
              body.getUnits().insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(PtolemyUtilities.arraycopyMethod.makeRef(),argumentList)),unit);
            }
            body.getUnits().remove(unit);
            doneSomething=true;
          }
        }
      }
 else       if (unit instanceof AssignStmt) {
        AssignStmt stmt=(AssignStmt)unit;
        stmt.getLeftOp().getType();
        if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof LengthExpr) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          LengthExpr lengthExpr=(LengthExpr)stmt.getRightOp();
          Local baseLocal=(Local)lengthExpr.getOp();
          if (debug) {
            System.out.println("String_Node_Str" + baseLocal);
          }
          Map fieldToReplacementArrayLocal=(Map)localToFieldToLocal.get(baseLocal);
          if (fieldToReplacementArrayLocal != null) {
            doneSomething=true;
            List replacementList=new ArrayList(fieldToReplacementArrayLocal.keySet());
            Collections.sort(replacementList,new Comparator(){
              public int compare(              Object o1,              Object o2){
                SootField f1=(SootField)o1;
                SootField f2=(SootField)o2;
                return f1.getName().compareTo(f2.getName());
              }
            }
);
            SootField field=(SootField)replacementList.get(replacementList.size() - 1);
            if (debug) {
              System.out.println("String_Node_Str" + fieldToReplacementArrayLocal.get(field));
            }
            lengthExpr.setOp((Local)fieldToReplacementArrayLocal.get(field));
            if (debug) {
              System.out.println("String_Node_Str" + unit);
            }
          }
        }
 else         if (stmt.getLeftOp() instanceof InstanceFieldRef) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          InstanceFieldRef r=(InstanceFieldRef)stmt.getLeftOp();
          SootField field=r.getField();
          if (r.getBase().getType() instanceof RefType) {
            RefType type=(RefType)r.getBase().getType();
            if (SootUtilities.derivesFrom(type.getSootClass(),PtolemyUtilities.tokenClass)) {
              if (debug) {
                System.out.println("String_Node_Str" + unit + "String_Node_Str");
              }
              Local baseLocal=(Local)r.getBase();
              Local instanceLocal=_getInstanceLocal(body,baseLocal,field,localToFieldToLocal,debug);
              if (debug) {
                System.out.println("String_Node_Str" + instanceLocal);
              }
              if (instanceLocal != null) {
                stmt.getLeftOpBox().setValue(instanceLocal);
                doneSomething=true;
              }
            }
          }
        }
 else         if (stmt.getRightOp() instanceof InstanceFieldRef) {
          if (debug) {
            System.out.println("String_Node_Str");
          }
          InstanceFieldRef r=(InstanceFieldRef)stmt.getRightOp();
          SootField field=r.getField();
          if (r.getBase().getType() instanceof RefType) {
            RefType type=(RefType)r.getBase().getType();
            if (SootUtilities.derivesFrom(type.getSootClass(),PtolemyUtilities.tokenClass)) {
              if (debug) {
                System.out.println("String_Node_Str" + unit + "String_Node_Str");
              }
              Local baseLocal=(Local)r.getBase();
              Local instanceLocal=_getInstanceLocal(body,baseLocal,field,localToFieldToLocal,debug);
              if (debug) {
                System.out.println("String_Node_Str" + instanceLocal);
              }
              if (instanceLocal != null) {
                stmt.getRightOpBox().setValue(instanceLocal);
                doneSomething=true;
              }
            }
          }
        }
      }
    }
  }
  if (debug) {
    System.out.println("String_Node_Str" + entityClass);
  }
  for (Iterator methods=entityClass.getMethods().iterator(); methods.hasNext(); ) {
    SootMethod method=(SootMethod)methods.next();
    if (debug) {
      System.out.println("String_Node_Str" + method);
    }
    JimpleBody body=(JimpleBody)method.retrieveActiveBody();
    for (Iterator units=body.getUnits().snapshotIterator(); units.hasNext(); ) {
      Unit unit=(Unit)units.next();
      if (debug) {
        System.out.println("String_Node_Str" + unit);
      }
      if (unit instanceof AssignStmt) {
        AssignStmt stmt=(AssignStmt)unit;
        Type assignmentType=stmt.getLeftOp().getType();
        if (PtolemyUtilities.isTokenType(assignmentType)) {
          if (stmt.getLeftOp() instanceof Local && (stmt.getRightOp() instanceof Local || stmt.getRightOp() instanceof Constant)) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            doneSomething|=_handleImmediateAssignment(body,stmt,localToFieldToLocal,localToIsNotNullLocal,stmt.getLeftOp(),stmt.getRightOp(),debug);
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof CastExpr) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            Value rightLocal=((CastExpr)stmt.getRightOp()).getOp();
            doneSomething|=_handleImmediateAssignment(body,stmt,localToFieldToLocal,localToIsNotNullLocal,stmt.getLeftOp(),rightLocal,debug);
          }
 else           if (stmt.getLeftOp() instanceof FieldRef && stmt.getRightOp() instanceof Local) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            FieldRef oldFieldRef=(FieldRef)stmt.getLeftOp();
            SootField field=oldFieldRef.getField();
            Map fieldToReplacementField=(Map)entityFieldToTokenFieldToReplacementField.get(field);
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getRightOp());
            if ((fieldToReplacementLocal != null) && (fieldToReplacementField != null)) {
              doneSomething=true;
{
                SootField replacementField=(SootField)entityFieldToIsNotNullField.get(field);
                FieldRef isNotNullFieldRef;
                if (oldFieldRef instanceof InstanceFieldRef) {
                  isNotNullFieldRef=Jimple.v().newInstanceFieldRef(((InstanceFieldRef)oldFieldRef).getBase(),replacementField.makeRef());
                }
 else {
                  isNotNullFieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(isNotNullFieldRef,(Local)localToIsNotNullLocal.get(stmt.getRightOp())),unit);
              }
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementField.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                SootField replacementField=(SootField)entry.getValue();
                Local replacementLocal=(Local)fieldToReplacementLocal.get(tokenField);
                if (debug) {
                  System.out.println("String_Node_Str" + replacementLocal);
                }
                FieldRef fieldRef;
                if (stmt.getLeftOp() instanceof InstanceFieldRef) {
                  Local base=(Local)((InstanceFieldRef)stmt.getLeftOp()).getBase();
                  fieldRef=Jimple.v().newInstanceFieldRef(base,replacementField.makeRef());
                }
 else {
                  fieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(fieldRef,replacementLocal),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof FieldRef) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            FieldRef oldFieldRef=(FieldRef)stmt.getRightOp();
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            SootField field=oldFieldRef.getField();
            Map fieldToReplacementField=(Map)entityFieldToTokenFieldToReplacementField.get(field);
            boolean isSingleton=false;
            if (field.getName().equals("String_Node_Str") || field.getName().equals("String_Node_Str") || field.getName().equals("String_Node_Str")|| field.getName().equals("String_Node_Str")) {
              isSingleton=true;
            }
            if ((isSingleton) && (fieldToReplacementLocal != null)) {
              doneSomething=true;
              body.getUnits().insertBefore(Jimple.v().newAssignStmt((Local)localToIsNotNullLocal.get(stmt.getLeftOp()),IntConstant.v(1)),unit);
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator localFields=fieldToReplacementLocal.entrySet().iterator(); localFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)localFields.next();
                SootField localField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + localField);
                }
                if (localField.getName().equals("String_Node_Str")) {
                  Local replacementLocal=(Local)entry.getValue();
                  body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,NullConstant.v()),unit);
                }
 else                 if (localField.getName().equals("String_Node_Str")) {
                  Local replacementLocal=(Local)fieldToReplacementLocal.get(localField);
                  if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,IntConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,LongConstant.v(1)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,LongConstant.v(0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,DoubleConstant.v(1.0)),unit);
                  }
 else                   if (field.getSignature().equals("String_Node_Str")) {
                    body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,DoubleConstant.v(0.0)),unit);
                  }
                }
 else {
                  throw new RuntimeException("String_Node_Str" + localField.getSignature());
                }
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
 else             if ((fieldToReplacementLocal != null) && (fieldToReplacementField != null)) {
              doneSomething=true;
{
                SootField replacementField=(SootField)entityFieldToIsNotNullField.get(field);
                FieldRef isNotNullFieldRef;
                if (oldFieldRef instanceof InstanceFieldRef) {
                  isNotNullFieldRef=Jimple.v().newInstanceFieldRef(((InstanceFieldRef)oldFieldRef).getBase(),replacementField.makeRef());
                }
 else {
                  isNotNullFieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt((Local)localToIsNotNullLocal.get(stmt.getLeftOp()),isNotNullFieldRef),unit);
              }
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementField.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                SootField replacementField=(SootField)entry.getValue();
                Local replacementLocal=(Local)fieldToReplacementLocal.get(tokenField);
                FieldRef fieldRef;
                if (stmt.getRightOp() instanceof InstanceFieldRef) {
                  Local base=(Local)((InstanceFieldRef)stmt.getRightOp()).getBase();
                  fieldRef=Jimple.v().newInstanceFieldRef(base,replacementField.makeRef());
                }
 else {
                  fieldRef=Jimple.v().newStaticFieldRef(replacementField.makeRef());
                }
                if (debug) {
                  System.out.println("String_Node_Str" + replacementLocal);
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,fieldRef),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof ArrayRef && stmt.getRightOp() instanceof Local) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            ArrayRef arrayRef=(ArrayRef)stmt.getLeftOp();
            Local baseLocal=(Local)arrayRef.getBase();
            Map fieldToReplacementArrayLocal=(Map)localToFieldToLocal.get(baseLocal);
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getRightOp());
            if (debug) {
              System.out.println("String_Node_Str" + fieldToReplacementArrayLocal);
            }
            if (debug) {
              System.out.println("String_Node_Str" + fieldToReplacementLocal);
            }
            if ((fieldToReplacementLocal != null) && (fieldToReplacementArrayLocal != null)) {
              doneSomething=true;
              body.getUnits().insertBefore(Jimple.v().newAssignStmt(Jimple.v().newArrayRef((Local)localToIsNotNullLocal.get(baseLocal),arrayRef.getIndex()),(Local)localToIsNotNullLocal.get(stmt.getRightOp())),unit);
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementLocal.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Local replacementArrayLocal=(Local)fieldToReplacementArrayLocal.get(tokenField);
                Local replacementLocal=(Local)entry.getValue();
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(Jimple.v().newArrayRef(replacementArrayLocal,arrayRef.getIndex()),replacementLocal),unit);
              }
              body.getUnits().remove(unit);
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof ArrayRef) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            ArrayRef arrayRef=(ArrayRef)stmt.getRightOp();
            Map fieldToReplacementLocal=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            Local baseLocal=(Local)arrayRef.getBase();
            Map fieldToReplacementArrayLocal=(Map)localToFieldToLocal.get(baseLocal);
            if ((fieldToReplacementLocal != null) && (fieldToReplacementArrayLocal != null)) {
              doneSomething=true;
              body.getUnits().insertBefore(Jimple.v().newAssignStmt((Local)localToIsNotNullLocal.get(stmt.getLeftOp()),Jimple.v().newArrayRef((Local)localToIsNotNullLocal.get(baseLocal),arrayRef.getIndex())),unit);
              if (debug) {
                System.out.println("String_Node_Str" + stmt.getLeftOp());
              }
              for (Iterator tokenFields=fieldToReplacementLocal.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Local replacementArrayLocal=(Local)fieldToReplacementArrayLocal.get(tokenField);
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + replacementLocal);
                }
                if (debug) {
                  System.out.println("String_Node_Str" + replacementArrayLocal);
                }
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,Jimple.v().newArrayRef(replacementArrayLocal,arrayRef.getIndex())),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof NewArrayExpr) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            NewArrayExpr newExpr=(NewArrayExpr)stmt.getRightOp();
            Map map=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            if (map != null) {
              doneSomething=true;
              Type isNotNullType=SootUtilities.createIsomorphicType(newExpr.getBaseType(),BooleanType.v());
              Local isNotNullLocal=(Local)localToIsNotNullLocal.get(stmt.getLeftOp());
              body.getUnits().insertBefore(Jimple.v().newAssignStmt(isNotNullLocal,Jimple.v().newNewArrayExpr(isNotNullType,newExpr.getSize())),unit);
              for (Iterator tokenFields=map.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Type replacementType=SootUtilities.createIsomorphicType(newExpr.getBaseType(),tokenField.getType());
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,Jimple.v().newNewArrayExpr(replacementType,newExpr.getSize())),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
 else           if (stmt.getLeftOp() instanceof Local && stmt.getRightOp() instanceof NewExpr) {
            if (debug) {
              System.out.println("String_Node_Str");
            }
            stmt.getRightOp();
            Map map=(Map)localToFieldToLocal.get(stmt.getLeftOp());
            if (map != null) {
              doneSomething=true;
              Local isNotNullLocal=(Local)localToIsNotNullLocal.get(stmt.getLeftOp());
              if (debug) {
                System.out.println("String_Node_Str" + stmt);
              }
              body.getUnits().insertBefore(Jimple.v().newAssignStmt(isNotNullLocal,IntConstant.v(1)),unit);
              for (Iterator tokenFields=map.entrySet().iterator(); tokenFields.hasNext(); ) {
                Map.Entry entry=(Map.Entry)tokenFields.next();
                SootField tokenField=(SootField)entry.getKey();
                Local replacementLocal=(Local)entry.getValue();
                if (debug) {
                  System.out.println("String_Node_Str" + tokenField);
                }
                Value replacementValue=_getNullValueForType(replacementLocal.getType());
                body.getUnits().insertBefore(Jimple.v().newAssignStmt(replacementLocal,replacementValue),unit);
              }
              stmt.getRightOpBox().setValue(NullConstant.v());
            }
          }
        }
      }
      for (Iterator boxes=unit.getUseAndDefBoxes().iterator(); boxes.hasNext(); ) {
        ValueBox box=(ValueBox)boxes.next();
        Value value=box.getValue();
        if (value instanceof BinopExpr) {
          BinopExpr expr=(BinopExpr)value;
          boolean op1IsToken=PtolemyUtilities.isTokenType(expr.getOp1().getType());
          boolean op2IsToken=PtolemyUtilities.isTokenType(expr.getOp2().getType());
          if (op1IsToken && op2IsToken) {
          }
 else           if (op1IsToken && expr.getOp2().getType().equals(NullType.v())) {
            doneSomething=true;
            Local isNotNullLocal=(Local)localToIsNotNullLocal.get(expr.getOp1());
            if (isNotNullLocal != null) {
              if (debug) {
                System.out.println("String_Node_Str" + expr);
              }
              Value nullValue;
              if (isNotNullLocal.getType().equals(BooleanType.v())) {
                nullValue=IntConstant.v(0);
              }
 else {
                nullValue=NullConstant.v();
              }
              if (expr instanceof EqExpr) {
                box.setValue(Jimple.v().newEqExpr(isNotNullLocal,nullValue));
              }
 else               if (expr instanceof NeExpr) {
                box.setValue(Jimple.v().newNeExpr(isNotNullLocal,nullValue));
              }
            }
          }
 else           if (op2IsToken && expr.getOp1().getType().equals(NullType.v())) {
            doneSomething=true;
            Local isNotNullLocal=(Local)localToIsNotNullLocal.get(expr.getOp2());
            if (isNotNullLocal != null) {
              Value nullValue;
              if (isNotNullLocal.getType().equals(BooleanType.v())) {
                nullValue=IntConstant.v(0);
              }
 else {
                nullValue=NullConstant.v();
              }
              if (expr instanceof EqExpr) {
                box.setValue(Jimple.v().newEqExpr(isNotNullLocal,nullValue));
              }
 else               if (expr instanceof NeExpr) {
                box.setValue(Jimple.v().newNeExpr(isNotNullLocal,nullValue));
              }
            }
          }
        }
      }
    }
  }
}