Program: 197353
Project: 197353
Buggy source:
final void logAppTooSlow(ProcessRecord app,long startTime,String msg){
  if (true || IS_USER_BUILD) {
    return;
  }
  String tracesPath=SystemProperties.get("String_Node_Str",null);
  if (tracesPath == null || tracesPath.length() == 0) {
    return;
  }
  StrictMode.ThreadPolicy oldPolicy=StrictMode.allowThreadDiskReads();
  StrictMode.allowThreadDiskWrites();
  try {
    final File tracesFile=new File(tracesPath);
    final File tracesDir=tracesFile.getParentFile();
    final File tracesTmp=new File(tracesDir,"String_Node_Str");
    try {
      if (!tracesDir.exists()) {
        tracesFile.mkdirs();
        if (!SELinux.restorecon(tracesDir.getPath())) {
          return;
        }
      }
      FileUtils.setPermissions(tracesDir.getPath(),0775,-1,-1);
      if (tracesFile.exists()) {
        tracesTmp.delete();
        tracesFile.renameTo(tracesTmp);
      }
      StringBuilder sb=new StringBuilder();
      Time tobj=new Time();
      tobj.set(System.currentTimeMillis());
      sb.append(tobj.format("String_Node_Str"));
      sb.append("String_Node_Str");
      TimeUtils.formatDuration(SystemClock.uptimeMillis() - startTime,sb);
      sb.append("String_Node_Str");
      sb.append(msg);
      FileOutputStream fos=new FileOutputStream(tracesFile);
      fos.write(sb.toString().getBytes());
      if (app == null) {
        fos.write("String_Node_Str".getBytes());
      }
      fos.close();
      FileUtils.setPermissions(tracesFile.getPath(),0666,-1,-1);
    }
 catch (    IOException e) {
      Slog.w(TAG,"String_Node_Str" + tracesPath,e);
      return;
    }
    if (app != null) {
      ArrayList<Integer> firstPids=new ArrayList<Integer>();
      firstPids.add(app.pid);
      dumpStackTraces(tracesPath,firstPids,null,null,null);
    }
    File lastTracesFile=null;
    File curTracesFile=null;
    for (int i=9; i >= 0; i--) {
      String name=String.format(Locale.US,"String_Node_Str",i);
      curTracesFile=new File(tracesDir,name);
      if (curTracesFile.exists()) {
        if (lastTracesFile != null) {
          curTracesFile.renameTo(lastTracesFile);
        }
 else {
          curTracesFile.delete();
        }
      }
      lastTracesFile=curTracesFile;
    }
    tracesFile.renameTo(curTracesFile);
    if (tracesTmp.exists()) {
      tracesTmp.renameTo(tracesFile);
    }
  }
  finally {
    StrictMode.setThreadPolicy(oldPolicy);
  }
}

Fixed version (ground truth):
final void logAppTooSlow(ProcessRecord app,long startTime,String msg){
  if (true || IS_USER_BUILD) {
    return;
  }
  String tracesPath=SystemProperties.get("String_Node_Str",null);
  if (tracesPath == null || tracesPath.length() == 0) {
    return;
  }
  StrictMode.ThreadPolicy oldPolicy=StrictMode.allowThreadDiskReads();
  StrictMode.allowThreadDiskWrites();
  try {
    final File tracesFile=new File(tracesPath);
    final File tracesDir=tracesFile.getParentFile();
    final File tracesTmp=new File(tracesDir,"String_Node_Str");
    try {
      if (!tracesDir.exists()) {
        tracesDir.mkdirs();
        if (!SELinux.restorecon(tracesDir.getPath())) {
          return;
        }
      }
      FileUtils.setPermissions(tracesDir.getPath(),0775,-1,-1);
      if (tracesFile.exists()) {
        tracesTmp.delete();
        tracesFile.renameTo(tracesTmp);
      }
      StringBuilder sb=new StringBuilder();
      Time tobj=new Time();
      tobj.set(System.currentTimeMillis());
      sb.append(tobj.format("String_Node_Str"));
      sb.append("String_Node_Str");
      TimeUtils.formatDuration(SystemClock.uptimeMillis() - startTime,sb);
      sb.append("String_Node_Str");
      sb.append(msg);
      FileOutputStream fos=new FileOutputStream(tracesFile);
      fos.write(sb.toString().getBytes());
      if (app == null) {
        fos.write("String_Node_Str".getBytes());
      }
      fos.close();
      FileUtils.setPermissions(tracesFile.getPath(),0666,-1,-1);
    }
 catch (    IOException e) {
      Slog.w(TAG,"String_Node_Str" + tracesPath,e);
      return;
    }
    if (app != null) {
      ArrayList<Integer> firstPids=new ArrayList<Integer>();
      firstPids.add(app.pid);
      dumpStackTraces(tracesPath,firstPids,null,null,null);
    }
    File lastTracesFile=null;
    File curTracesFile=null;
    for (int i=9; i >= 0; i--) {
      String name=String.format(Locale.US,"String_Node_Str",i);
      curTracesFile=new File(tracesDir,name);
      if (curTracesFile.exists()) {
        if (lastTracesFile != null) {
          curTracesFile.renameTo(lastTracesFile);
        }
 else {
          curTracesFile.delete();
        }
      }
      lastTracesFile=curTracesFile;
    }
    tracesFile.renameTo(curTracesFile);
    if (tracesTmp.exists()) {
      tracesTmp.renameTo(tracesFile);
    }
  }
  finally {
    StrictMode.setThreadPolicy(oldPolicy);
  }
}