Program: 872
Project: 872
Buggy source:
public ParcelFileDescriptor getStatsOverTime(long minTime){
  mAm.mContext.enforceCallingOrSelfPermission(android.Manifest.permission.PACKAGE_USAGE_STATS,null);
  mWriteLock.lock();
  try {
    Parcel current=Parcel.obtain();
    long curTime;
synchronized (mAm) {
      mProcessStats.mTimePeriodEndRealtime=SystemClock.elapsedRealtime();
      mProcessStats.writeToParcel(current,0);
      curTime=mProcessStats.mTimePeriodEndRealtime - mProcessStats.mTimePeriodStartRealtime;
    }
    if (curTime < minTime) {
      ArrayList<String> files=getCommittedFiles(0,false,true);
      if (files != null && files.size() > 0) {
        current.setDataPosition(0);
        ProcessStats stats=ProcessStats.CREATOR.createFromParcel(current);
        current.recycle();
        int i=0;
        while (i < files.size() && (stats.mTimePeriodEndRealtime - stats.mTimePeriodStartRealtime) < minTime) {
          AtomicFile file=new AtomicFile(new File(files.get(i)));
          i++;
          ProcessStats moreStats=new ProcessStats(false);
          readLocked(moreStats,file);
          if (moreStats.mReadError == null) {
            stats.add(moreStats);
            StringBuilder sb=new StringBuilder();
            sb.append("String_Node_Str");
            sb.append(moreStats.mTimePeriodStartClockStr);
            sb.append("String_Node_Str");
            TimeUtils.formatDuration(moreStats.mTimePeriodEndRealtime - moreStats.mTimePeriodStartRealtime,sb);
            Slog.i(TAG,sb.toString());
          }
 else {
            Slog.w(TAG,"String_Node_Str" + files.get(i - 1) + "String_Node_Str"+ moreStats.mReadError);
            continue;
          }
        }
        current=Parcel.obtain();
        stats.writeToParcel(current,0);
      }
    }
    final byte[] outData=current.marshall();
    current.recycle();
    final ParcelFileDescriptor[] fds=ParcelFileDescriptor.createPipe();
    Thread thr=new Thread("String_Node_Str"){
      public void run(){
        FileOutputStream fout=new ParcelFileDescriptor.AutoCloseOutputStream(fds[1]);
        try {
          fout.write(outData);
          fout.close();
        }
 catch (        IOException e) {
          Slog.w(TAG,"String_Node_Str",e);
        }
      }
    }
;
    thr.start();
    return fds[0];
  }
 catch (  IOException e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
 finally {
    mWriteLock.unlock();
  }
  return null;
}

Fixed version (ground truth):
public ParcelFileDescriptor getStatsOverTime(long minTime){
  mAm.mContext.enforceCallingOrSelfPermission(android.Manifest.permission.PACKAGE_USAGE_STATS,null);
  mWriteLock.lock();
  try {
    Parcel current=Parcel.obtain();
    long curTime;
synchronized (mAm) {
      mProcessStats.mTimePeriodEndRealtime=SystemClock.elapsedRealtime();
      mProcessStats.writeToParcel(current,0);
      curTime=mProcessStats.mTimePeriodEndRealtime - mProcessStats.mTimePeriodStartRealtime;
    }
    if (curTime < minTime) {
      ArrayList<String> files=getCommittedFiles(0,false,true);
      if (files != null && files.size() > 0) {
        current.setDataPosition(0);
        ProcessStats stats=ProcessStats.CREATOR.createFromParcel(current);
        current.recycle();
        int i=files.size() - 1;
        while (i >= 0 && (stats.mTimePeriodEndRealtime - stats.mTimePeriodStartRealtime) < minTime) {
          AtomicFile file=new AtomicFile(new File(files.get(i)));
          i--;
          ProcessStats moreStats=new ProcessStats(false);
          readLocked(moreStats,file);
          if (moreStats.mReadError == null) {
            stats.add(moreStats);
            StringBuilder sb=new StringBuilder();
            sb.append("String_Node_Str");
            sb.append(moreStats.mTimePeriodStartClockStr);
            sb.append("String_Node_Str");
            TimeUtils.formatDuration(moreStats.mTimePeriodEndRealtime - moreStats.mTimePeriodStartRealtime,sb);
            Slog.i(TAG,sb.toString());
          }
 else {
            Slog.w(TAG,"String_Node_Str" + files.get(i + 1) + "String_Node_Str"+ moreStats.mReadError);
            continue;
          }
        }
        current=Parcel.obtain();
        stats.writeToParcel(current,0);
      }
    }
    final byte[] outData=current.marshall();
    current.recycle();
    final ParcelFileDescriptor[] fds=ParcelFileDescriptor.createPipe();
    Thread thr=new Thread("String_Node_Str"){
      public void run(){
        FileOutputStream fout=new ParcelFileDescriptor.AutoCloseOutputStream(fds[1]);
        try {
          fout.write(outData);
          fout.close();
        }
 catch (        IOException e) {
          Slog.w(TAG,"String_Node_Str",e);
        }
      }
    }
;
    thr.start();
    return fds[0];
  }
 catch (  IOException e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
 finally {
    mWriteLock.unlock();
  }
  return null;
}