Program: 195567
Project: 195567
Buggy source:
/** 
 * Prints a list of ServiceRecords (dumpsys activity services)
 */
void dumpServicesLocked(FileDescriptor fd,PrintWriter pw,String[] args,int opti,boolean dumpAll,boolean dumpClient,String dumpPackage){
  boolean needSep=false;
  boolean printedAnything=false;
  ItemMatcher matcher=new ItemMatcher();
  matcher.build(args,opti);
  pw.println("String_Node_Str");
  try {
    int[] users=mAm.getUsersLocked();
    for (    int user : users) {
      ServiceMap smap=getServiceMap(user);
      boolean printed=false;
      if (smap.mServicesByName.size() > 0) {
        long nowReal=SystemClock.elapsedRealtime();
        needSep=false;
        for (int si=0; si < smap.mServicesByName.size(); si++) {
          ServiceRecord r=smap.mServicesByName.valueAt(si);
          if (!matcher.match(r,r.name)) {
            continue;
          }
          if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
            continue;
          }
          if (!printed) {
            if (printedAnything) {
              pw.println();
            }
            pw.println("String_Node_Str" + user + "String_Node_Str");
            printed=true;
          }
          printedAnything=true;
          if (needSep) {
            pw.println();
          }
          pw.print("String_Node_Str");
          pw.println(r);
          if (dumpAll) {
            r.dump(pw,"String_Node_Str");
            needSep=true;
          }
 else {
            pw.print("String_Node_Str");
            pw.println(r.app);
            pw.print("String_Node_Str");
            TimeUtils.formatDuration(r.createTime,nowReal,pw);
            pw.print("String_Node_Str");
            pw.print(r.startRequested);
            pw.print("String_Node_Str");
            pw.println(r.connections.size());
            if (r.connections.size() > 0) {
              pw.println("String_Node_Str");
              for (int conni=0; conni < r.connections.size(); conni++) {
                ArrayList<ConnectionRecord> clist=r.connections.valueAt(conni);
                for (int i=0; i < clist.size(); i++) {
                  ConnectionRecord conn=clist.get(i);
                  pw.print("String_Node_Str");
                  pw.print(conn.binding.intent.intent.getIntent().toShortString(false,false,false,false));
                  pw.print("String_Node_Str");
                  ProcessRecord proc=conn.binding.client;
                  pw.println(proc != null ? proc.toShortString() : "String_Node_Str");
                }
              }
            }
          }
          if (dumpClient && r.app != null && r.app.thread != null) {
            pw.println("String_Node_Str");
            pw.flush();
            try {
              TransferPipe tp=new TransferPipe();
              try {
                r.app.thread.dumpService(tp.getWriteFd().getFileDescriptor(),r,args);
                tp.setBufferPrefix("String_Node_Str");
                tp.go(fd,2000);
              }
  finally {
                tp.kill();
              }
            }
 catch (            IOException e) {
              pw.println("String_Node_Str" + e);
            }
catch (            RemoteException e) {
              pw.println("String_Node_Str");
            }
            needSep=true;
          }
        }
        needSep|=printed;
      }
      printed=false;
      for (int si=0, SN=smap.mDelayedStartList.size(); si < SN; si++) {
        ServiceRecord r=smap.mDelayedStartList.get(si);
        if (!matcher.match(r,r.name)) {
          continue;
        }
        if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
          continue;
        }
        if (!printed) {
          if (printedAnything) {
            pw.println();
          }
          pw.println("String_Node_Str" + user + "String_Node_Str");
          printed=true;
        }
        printedAnything=true;
        pw.print("String_Node_Str");
        pw.println(r);
      }
      printed=false;
      for (int si=0, SN=smap.mStartingBackground.size(); si < SN; si++) {
        ServiceRecord r=smap.mStartingBackground.get(si);
        if (!matcher.match(r,r.name)) {
          continue;
        }
        if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
          continue;
        }
        if (!printed) {
          if (printedAnything) {
            pw.println();
          }
          pw.println("String_Node_Str" + user + "String_Node_Str");
          printed=true;
        }
        printedAnything=true;
        pw.print("String_Node_Str");
        pw.println(r);
      }
    }
  }
 catch (  Exception e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
  if (mPendingServices.size() > 0) {
    boolean printed=false;
    for (int i=0; i < mPendingServices.size(); i++) {
      ServiceRecord r=mPendingServices.get(i);
      if (!matcher.match(r,r.name)) {
        continue;
      }
      if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
        continue;
      }
      printedAnything=true;
      if (!printed) {
        if (needSep)         pw.println();
        needSep=true;
        pw.println("String_Node_Str");
        printed=true;
      }
      pw.print("String_Node_Str");
      pw.println(r);
      r.dump(pw,"String_Node_Str");
    }
    needSep=true;
  }
  if (mRestartingServices.size() > 0) {
    boolean printed=false;
    for (int i=0; i < mRestartingServices.size(); i++) {
      ServiceRecord r=mRestartingServices.get(i);
      if (!matcher.match(r,r.name)) {
        continue;
      }
      if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
        continue;
      }
      printedAnything=true;
      if (!printed) {
        if (needSep)         pw.println();
        needSep=true;
        pw.println("String_Node_Str");
        printed=true;
      }
      pw.print("String_Node_Str");
      pw.println(r);
      r.dump(pw,"String_Node_Str");
    }
    needSep=true;
  }
  if (mDestroyingServices.size() > 0) {
    boolean printed=false;
    for (int i=0; i < mDestroyingServices.size(); i++) {
      ServiceRecord r=mDestroyingServices.get(i);
      if (!matcher.match(r,r.name)) {
        continue;
      }
      if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
        continue;
      }
      printedAnything=true;
      if (!printed) {
        if (needSep)         pw.println();
        needSep=true;
        pw.println("String_Node_Str");
        printed=true;
      }
      pw.print("String_Node_Str");
      pw.println(r);
      r.dump(pw,"String_Node_Str");
    }
    needSep=true;
  }
  if (dumpAll) {
    boolean printed=false;
    for (int ic=0; ic < mServiceConnections.size(); ic++) {
      ArrayList<ConnectionRecord> r=mServiceConnections.valueAt(ic);
      for (int i=0; i < r.size(); i++) {
        ConnectionRecord cr=r.get(i);
        if (!matcher.match(cr.binding.service,cr.binding.service.name)) {
          continue;
        }
        if (dumpPackage != null && (cr.binding.client == null || !dumpPackage.equals(cr.binding.client.info.packageName))) {
          continue;
        }
        printedAnything=true;
        if (!printed) {
          if (needSep)           pw.println();
          needSep=true;
          pw.println("String_Node_Str");
          printed=true;
        }
        pw.print("String_Node_Str");
        pw.println(cr);
        cr.dump(pw,"String_Node_Str");
      }
    }
  }
  if (!printedAnything) {
    pw.println("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Prints a list of ServiceRecords (dumpsys activity services)
 */
void dumpServicesLocked(FileDescriptor fd,PrintWriter pw,String[] args,int opti,boolean dumpAll,boolean dumpClient,String dumpPackage){
  boolean needSep=false;
  boolean printedAnything=false;
  ItemMatcher matcher=new ItemMatcher();
  matcher.build(args,opti);
  pw.println("String_Node_Str");
  try {
    if (mLastAnrDump != null) {
      pw.println("String_Node_Str");
      pw.print(mLastAnrDump);
      pw.println();
    }
    int[] users=mAm.getUsersLocked();
    for (    int user : users) {
      ServiceMap smap=getServiceMap(user);
      boolean printed=false;
      if (smap.mServicesByName.size() > 0) {
        long nowReal=SystemClock.elapsedRealtime();
        needSep=false;
        for (int si=0; si < smap.mServicesByName.size(); si++) {
          ServiceRecord r=smap.mServicesByName.valueAt(si);
          if (!matcher.match(r,r.name)) {
            continue;
          }
          if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
            continue;
          }
          if (!printed) {
            if (printedAnything) {
              pw.println();
            }
            pw.println("String_Node_Str" + user + "String_Node_Str");
            printed=true;
          }
          printedAnything=true;
          if (needSep) {
            pw.println();
          }
          pw.print("String_Node_Str");
          pw.println(r);
          if (dumpAll) {
            r.dump(pw,"String_Node_Str");
            needSep=true;
          }
 else {
            pw.print("String_Node_Str");
            pw.println(r.app);
            pw.print("String_Node_Str");
            TimeUtils.formatDuration(r.createTime,nowReal,pw);
            pw.print("String_Node_Str");
            pw.print(r.startRequested);
            pw.print("String_Node_Str");
            pw.println(r.connections.size());
            if (r.connections.size() > 0) {
              pw.println("String_Node_Str");
              for (int conni=0; conni < r.connections.size(); conni++) {
                ArrayList<ConnectionRecord> clist=r.connections.valueAt(conni);
                for (int i=0; i < clist.size(); i++) {
                  ConnectionRecord conn=clist.get(i);
                  pw.print("String_Node_Str");
                  pw.print(conn.binding.intent.intent.getIntent().toShortString(false,false,false,false));
                  pw.print("String_Node_Str");
                  ProcessRecord proc=conn.binding.client;
                  pw.println(proc != null ? proc.toShortString() : "String_Node_Str");
                }
              }
            }
          }
          if (dumpClient && r.app != null && r.app.thread != null) {
            pw.println("String_Node_Str");
            pw.flush();
            try {
              TransferPipe tp=new TransferPipe();
              try {
                r.app.thread.dumpService(tp.getWriteFd().getFileDescriptor(),r,args);
                tp.setBufferPrefix("String_Node_Str");
                tp.go(fd,2000);
              }
  finally {
                tp.kill();
              }
            }
 catch (            IOException e) {
              pw.println("String_Node_Str" + e);
            }
catch (            RemoteException e) {
              pw.println("String_Node_Str");
            }
            needSep=true;
          }
        }
        needSep|=printed;
      }
      printed=false;
      for (int si=0, SN=smap.mDelayedStartList.size(); si < SN; si++) {
        ServiceRecord r=smap.mDelayedStartList.get(si);
        if (!matcher.match(r,r.name)) {
          continue;
        }
        if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
          continue;
        }
        if (!printed) {
          if (printedAnything) {
            pw.println();
          }
          pw.println("String_Node_Str" + user + "String_Node_Str");
          printed=true;
        }
        printedAnything=true;
        pw.print("String_Node_Str");
        pw.println(r);
      }
      printed=false;
      for (int si=0, SN=smap.mStartingBackground.size(); si < SN; si++) {
        ServiceRecord r=smap.mStartingBackground.get(si);
        if (!matcher.match(r,r.name)) {
          continue;
        }
        if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
          continue;
        }
        if (!printed) {
          if (printedAnything) {
            pw.println();
          }
          pw.println("String_Node_Str" + user + "String_Node_Str");
          printed=true;
        }
        printedAnything=true;
        pw.print("String_Node_Str");
        pw.println(r);
      }
    }
  }
 catch (  Exception e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
  if (mPendingServices.size() > 0) {
    boolean printed=false;
    for (int i=0; i < mPendingServices.size(); i++) {
      ServiceRecord r=mPendingServices.get(i);
      if (!matcher.match(r,r.name)) {
        continue;
      }
      if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
        continue;
      }
      printedAnything=true;
      if (!printed) {
        if (needSep)         pw.println();
        needSep=true;
        pw.println("String_Node_Str");
        printed=true;
      }
      pw.print("String_Node_Str");
      pw.println(r);
      r.dump(pw,"String_Node_Str");
    }
    needSep=true;
  }
  if (mRestartingServices.size() > 0) {
    boolean printed=false;
    for (int i=0; i < mRestartingServices.size(); i++) {
      ServiceRecord r=mRestartingServices.get(i);
      if (!matcher.match(r,r.name)) {
        continue;
      }
      if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
        continue;
      }
      printedAnything=true;
      if (!printed) {
        if (needSep)         pw.println();
        needSep=true;
        pw.println("String_Node_Str");
        printed=true;
      }
      pw.print("String_Node_Str");
      pw.println(r);
      r.dump(pw,"String_Node_Str");
    }
    needSep=true;
  }
  if (mDestroyingServices.size() > 0) {
    boolean printed=false;
    for (int i=0; i < mDestroyingServices.size(); i++) {
      ServiceRecord r=mDestroyingServices.get(i);
      if (!matcher.match(r,r.name)) {
        continue;
      }
      if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
        continue;
      }
      printedAnything=true;
      if (!printed) {
        if (needSep)         pw.println();
        needSep=true;
        pw.println("String_Node_Str");
        printed=true;
      }
      pw.print("String_Node_Str");
      pw.println(r);
      r.dump(pw,"String_Node_Str");
    }
    needSep=true;
  }
  if (dumpAll) {
    boolean printed=false;
    for (int ic=0; ic < mServiceConnections.size(); ic++) {
      ArrayList<ConnectionRecord> r=mServiceConnections.valueAt(ic);
      for (int i=0; i < r.size(); i++) {
        ConnectionRecord cr=r.get(i);
        if (!matcher.match(cr.binding.service,cr.binding.service.name)) {
          continue;
        }
        if (dumpPackage != null && (cr.binding.client == null || !dumpPackage.equals(cr.binding.client.info.packageName))) {
          continue;
        }
        printedAnything=true;
        if (!printed) {
          if (needSep)           pw.println();
          needSep=true;
          pw.println("String_Node_Str");
          printed=true;
        }
        pw.print("String_Node_Str");
        pw.println(cr);
        cr.dump(pw,"String_Node_Str");
      }
    }
  }
  if (!printedAnything) {
    pw.println("String_Node_Str");
  }
}