nus-yam/ex-repair huggingface dataset:
Program: 193018
Project: 193018
Buggy source:
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
        mStatsChanged=true;
      }
    }
  }
  persistActiveStats();
}

Fixed version (ground truth):
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
      }
      mAppIdleRollingWindow.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
      mAppIdleRollingWindow.updateBeginIdleTime(packageName,deviceUsageTime);
      mStatsChanged=true;
    }
  }
  persistActiveStats();
}
Program: 193019
Project: 193019
Buggy source:
private static void mergePackageStats(IntervalStats dst,IntervalStats src){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    final UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dst.packageStats.put(packageName,new UsageStats(srcStats));
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
  }
}

Fixed version (ground truth):
private static void mergePackageStats(IntervalStats dst,IntervalStats src,final long deviceUsageTime){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dstStats=new UsageStats(srcStats);
      dst.packageStats.put(packageName,dstStats);
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
    if (dstStats.mBeginIdleTime > deviceUsageTime) {
      dstStats.mBeginIdleTime=deviceUsageTime;
    }
  }
}
Program: 193020
Project: 193020
Buggy source:
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats);
}

Fixed version (ground truth):
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats,deviceUsageTime);
}
Program: 193022
Project: 193022
Buggy source:
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp,deviceUsageTime);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}
Program: 193023
Project: 193023
Buggy source:
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(long currentTimeMillis){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,sPackageStatsMerger);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}

Fixed version (ground truth):
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(final long currentTimeMillis,final long deviceUsageTime){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,new StatCombiner<IntervalStats>(){
    @Override public void combine(    IntervalStats stats,    boolean mutable,    List<IntervalStats> accumulatedResult){
      IntervalStats accum;
      if (accumulatedResult.isEmpty()) {
        accum=new IntervalStats();
        accum.beginTime=stats.beginTime;
        accumulatedResult.add(accum);
      }
 else {
        accum=accumulatedResult.get(0);
      }
      mergePackageStats(accum,stats,deviceUsageTime);
    }
  }
);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY],deviceUsageTime);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}
Program: 193025
Project: 193025
Buggy source:
/** 
 * Retrieves whether the current DPM allows use of the Profile Challenge.
 */
public boolean isSeparateProfileChallengeAllowed(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (!info.isManagedProfile()) {
    return false;
  }
  return getDevicePolicyManager().isSeparateProfileChallengeAllowed(userHandle);
}

Fixed version (ground truth):
/** 
 * Retrieves whether the current DPM allows use of the Profile Challenge.
 */
public boolean isSeparateProfileChallengeAllowed(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (info == null || !info.isManagedProfile()) {
    return false;
  }
  return getDevicePolicyManager().isSeparateProfileChallengeAllowed(userHandle);
}
Program: 193026
Project: 193026
Buggy source:
/** 
 * Retrieves whether the Separate Profile Challenge is enabled for this   {@param userHandle}.
 */
public boolean isSeparateProfileChallengeEnabled(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (!info.isManagedProfile()) {
    return false;
  }
  return getBoolean(SEPARATE_PROFILE_CHALLENGE_KEY,false,userHandle);
}

Fixed version (ground truth):
/** 
 * Retrieves whether the Separate Profile Challenge is enabled for this   {@param userHandle}.
 */
public boolean isSeparateProfileChallengeEnabled(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (info == null || !info.isManagedProfile()) {
    return false;
  }
  return getBoolean(SEPARATE_PROFILE_CHALLENGE_KEY,false,userHandle);
}
Program: 193027
Project: 193027
Buggy source:
@Override public boolean isDeviceSecure(int userId) throws RemoteException {
  userId=ActivityManager.handleIncomingUser(getCallingPid(),getCallingUid(),userId,false,true,"String_Node_Str",null);
  if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
    userId=resolveProfileParent(userId);
  }
  long token=Binder.clearCallingIdentity();
  try {
    return mLockPatternUtils.isSecure(userId);
  }
  finally {
    Binder.restoreCallingIdentity(token);
  }
}

Fixed version (ground truth):
@Override public boolean isDeviceSecure(int userId) throws RemoteException {
  userId=ActivityManager.handleIncomingUser(getCallingPid(),getCallingUid(),userId,false,true,"String_Node_Str",null);
  long token=Binder.clearCallingIdentity();
  try {
    if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
      userId=resolveProfileParent(userId);
    }
    return mLockPatternUtils.isSecure(userId);
  }
  finally {
    Binder.restoreCallingIdentity(token);
  }
}
Program: 193028
Project: 193028
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
    final int sequence=intent.getIntExtra("String_Node_Str",0);
    if (DEBUG)     Log.d(TAG,"String_Node_Str" + sequence + "String_Node_Str"+ mDelayedShowingSequence);
synchronized (KeyguardViewMediator.this) {
      doKeyguardLocked(null);
    }
  }
 else   if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
    int userId=intent.getIntExtra(Intent.EXTRA_USER_ID,0);
    if (userId != 0) {
synchronized (KeyguardViewMediator.this) {
        lockProfile(userId);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
    final int sequence=intent.getIntExtra("String_Node_Str",0);
    if (DEBUG)     Log.d(TAG,"String_Node_Str" + sequence + "String_Node_Str"+ mDelayedShowingSequence);
synchronized (KeyguardViewMediator.this) {
      if (mDelayedShowingSequence == sequence) {
        doKeyguardLocked(null);
      }
    }
  }
 else   if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
    int userId=intent.getIntExtra(Intent.EXTRA_USER_ID,0);
    if (userId != 0) {
synchronized (KeyguardViewMediator.this) {
        lockProfile(userId);
      }
    }
  }
}
Program: 193029
Project: 193029
Buggy source:
public void keyguardDoneDrawing(){
  mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
}

Fixed version (ground truth):
@Override public void keyguardDoneDrawing(){
  mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
}
Program: 193030
Project: 193030
Buggy source:
public void onBootCompleted(){
  mUpdateMonitor.dispatchBootCompleted();
synchronized (this) {
    mBootCompleted=true;
    if (mBootSendUserPresent) {
      sendUserPresentBroadcast();
    }
  }
}

Fixed version (ground truth):
@Override public void onBootCompleted(){
  mUpdateMonitor.dispatchBootCompleted();
synchronized (this) {
    mBootCompleted=true;
    if (mBootSendUserPresent) {
      sendUserPresentBroadcast();
    }
  }
}
Program: 193031
Project: 193031
Buggy source:
private void updateLockScreenTimeout(){
synchronized (mScreenLockTimeout) {
    boolean enable=(mAllowLockscreenWhenOn && mAwake && mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
    if (mLockScreenTimerActive != enable) {
      if (enable) {
        if (localLOGV)         Log.v(TAG,"String_Node_Str");
        mHandler.postDelayed(mScreenLockTimeout,mLockScreenTimeout);
      }
 else {
        if (localLOGV)         Log.v(TAG,"String_Node_Str");
        mHandler.removeCallbacks(mScreenLockTimeout);
      }
      mLockScreenTimerActive=enable;
    }
  }
}

Fixed version (ground truth):
private void updateLockScreenTimeout(){
synchronized (mScreenLockTimeout) {
    boolean enable=(mAllowLockscreenWhenOn && mAwake && mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
    if (mLockScreenTimerActive != enable) {
      if (enable) {
        if (localLOGV)         Log.v(TAG,"String_Node_Str");
        mHandler.removeCallbacks(mScreenLockTimeout);
        mHandler.postDelayed(mScreenLockTimeout,mLockScreenTimeout);
      }
 else {
        if (localLOGV)         Log.v(TAG,"String_Node_Str");
        mHandler.removeCallbacks(mScreenLockTimeout);
      }
      mLockScreenTimerActive=enable;
    }
  }
}
Program: 193034
Project: 193034
Buggy source:
private void insertTaskAtTop(TaskRecord task,ActivityRecord newActivity){
  if (task.isOverHomeStack()) {
    final TaskRecord nextTask=getNextTask(task);
    if (nextTask != null) {
      nextTask.setTaskToReturnTo(task.getTaskToReturnTo());
    }
  }
  if (isOnHomeDisplay()) {
    ActivityStack lastStack=mStackSupervisor.getLastStack();
    final boolean fromHome=lastStack.isHomeStack();
    if (!isHomeStack() && (fromHome || topTask() != task)) {
      task.setTaskToReturnTo(fromHome ? lastStack.topTask() == null ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType : APPLICATION_ACTIVITY_TYPE);
    }
  }
 else {
    task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
  }
  mTaskHistory.remove(task);
  int taskNdx=mTaskHistory.size();
  final boolean notShownWhenLocked=(newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) || (newActivity == null && task.topRunningActivityLocked() == null);
  if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) {
    while (--taskNdx >= 0) {
      final TaskRecord tmpTask=mTaskHistory.get(taskNdx);
      if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) || tmpTask.topRunningActivityLocked() == null) {
        break;
      }
    }
    ++taskNdx;
  }
  mTaskHistory.add(taskNdx,task);
  updateTaskMovement(task,true);
}

Fixed version (ground truth):
private void insertTaskAtTop(TaskRecord task,ActivityRecord newActivity){
  if (task.isOverHomeStack()) {
    final TaskRecord nextTask=getNextTask(task);
    if (nextTask != null) {
      nextTask.setTaskToReturnTo(task.getTaskToReturnTo());
    }
  }
  if (isOnHomeDisplay()) {
    ActivityStack lastStack=mStackSupervisor.getLastStack();
    final boolean fromHome=lastStack.isHomeStack();
    if (!isHomeStack() && (fromHome || topTask() != task)) {
      int returnToType=APPLICATION_ACTIVITY_TYPE;
      if (fromHome && StackId.allowTopTaskToReturnHome(mStackId)) {
        returnToType=lastStack.topTask() == null ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType;
      }
      task.setTaskToReturnTo(returnToType);
    }
  }
 else {
    task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
  }
  mTaskHistory.remove(task);
  int taskNdx=mTaskHistory.size();
  final boolean notShownWhenLocked=(newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) || (newActivity == null && task.topRunningActivityLocked() == null);
  if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) {
    while (--taskNdx >= 0) {
      final TaskRecord tmpTask=mTaskHistory.get(taskNdx);
      if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) || tmpTask.topRunningActivityLocked() == null) {
        break;
      }
    }
    ++taskNdx;
  }
  mTaskHistory.add(taskNdx,task);
  updateTaskMovement(task,true);
}
Program: 193037
Project: 193037
Buggy source:
final void activityStoppedLocked(ActivityRecord r,Bundle icicle,PersistableBundle persistentState,CharSequence description){
  if (r.state != ActivityState.STOPPING) {
    Slog.i(TAG,"String_Node_Str" + r);
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    return;
  }
  if (persistentState != null) {
    r.persistentState=persistentState;
    mService.notifyTaskPersisterLocked(r.task,false);
  }
  if (DEBUG_SAVED_STATE)   Slog.i(TAG_SAVED_STATE,"String_Node_Str" + r + "String_Node_Str"+ icicle);
  if (icicle != null) {
    r.icicle=icicle;
    r.haveState=true;
    r.launchCount=0;
    r.updateThumbnailLocked(null,description);
  }
  if (!r.stopped) {
    if (DEBUG_STATES)     Slog.v(TAG_STATES,"String_Node_Str" + r + "String_Node_Str");
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    r.stopped=true;
    r.state=ActivityState.STOPPED;
    if (getVisibleBehindActivity() == r) {
      mStackSupervisor.requestVisibleBehindLocked(r,false);
    }
    if (r.finishing) {
      r.clearOptionsLocked();
    }
 else {
      if (r.configDestroy) {
        destroyActivityLocked(r,true,"String_Node_Str");
        mStackSupervisor.resumeFocusedStackTopActivityLocked();
      }
 else {
        mStackSupervisor.updatePreviousProcessLocked(r);
      }
    }
  }
}

Fixed version (ground truth):
final void activityStoppedLocked(ActivityRecord r,Bundle icicle,PersistableBundle persistentState,CharSequence description){
  if (r.state != ActivityState.STOPPING) {
    Slog.i(TAG,"String_Node_Str" + r);
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    return;
  }
  if (persistentState != null) {
    r.persistentState=persistentState;
    mService.notifyTaskPersisterLocked(r.task,false);
  }
  if (DEBUG_SAVED_STATE)   Slog.i(TAG_SAVED_STATE,"String_Node_Str" + r + "String_Node_Str"+ icicle);
  if (icicle != null) {
    r.icicle=icicle;
    r.haveState=true;
    r.launchCount=0;
    r.updateThumbnailLocked(null,description);
  }
  if (!r.stopped) {
    if (DEBUG_STATES)     Slog.v(TAG_STATES,"String_Node_Str" + r + "String_Node_Str");
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    r.stopped=true;
    r.state=ActivityState.STOPPED;
    if (getVisibleBehindActivity() == r) {
      mStackSupervisor.requestVisibleBehindLocked(r,false);
    }
    if (r.finishing) {
      r.clearOptionsLocked();
    }
 else {
      if (r.deferRelaunchUntilPaused) {
        destroyActivityLocked(r,true,"String_Node_Str");
        mStackSupervisor.resumeFocusedStackTopActivityLocked();
      }
 else {
        mStackSupervisor.updatePreviousProcessLocked(r);
      }
    }
  }
}
Program: 193038
Project: 193038
Buggy source:
/** 
 * Perform the common clean-up of an activity record.  This is called both as part of destroyActivityLocked() (when destroying the client-side representation) and cleaning things up as a result of its hosting processing going away, in which case there is no remaining client-side state to destroy so only the cleanup here is needed. Note: Call before #removeActivityFromHistoryLocked.
 */
final void cleanUpActivityLocked(ActivityRecord r,boolean cleanServices,boolean setState){
  if (mResumedActivity == r) {
    mResumedActivity=null;
  }
  if (mPausingActivity == r) {
    mPausingActivity=null;
  }
  mService.resetFocusedActivityIfNeededLocked(r);
  r.configDestroy=false;
  r.frozenBeforeDestroy=false;
  if (setState) {
    if (DEBUG_STATES)     Slog.v(TAG_STATES,"String_Node_Str" + r + "String_Node_Str");
    r.state=ActivityState.DESTROYED;
    if (DEBUG_APP)     Slog.v(TAG_APP,"String_Node_Str" + r);
    r.app=null;
  }
  mStackSupervisor.mFinishingActivities.remove(r);
  mStackSupervisor.mWaitingVisibleActivities.remove(r);
  if (r.finishing && r.pendingResults != null) {
    for (    WeakReference<PendingIntentRecord> apr : r.pendingResults) {
      PendingIntentRecord rec=apr.get();
      if (rec != null) {
        mService.cancelIntentSenderLocked(rec,false);
      }
    }
    r.pendingResults=null;
  }
  if (cleanServices) {
    cleanUpActivityServicesLocked(r);
  }
  removeTimeoutsForActivityLocked(r);
  if (getVisibleBehindActivity() == r) {
    mStackSupervisor.requestVisibleBehindLocked(r,false);
  }
}

Fixed version (ground truth):
/** 
 * Perform the common clean-up of an activity record.  This is called both as part of destroyActivityLocked() (when destroying the client-side representation) and cleaning things up as a result of its hosting processing going away, in which case there is no remaining client-side state to destroy so only the cleanup here is needed. Note: Call before #removeActivityFromHistoryLocked.
 */
final void cleanUpActivityLocked(ActivityRecord r,boolean cleanServices,boolean setState){
  if (mResumedActivity == r) {
    mResumedActivity=null;
  }
  if (mPausingActivity == r) {
    mPausingActivity=null;
  }
  mService.resetFocusedActivityIfNeededLocked(r);
  r.deferRelaunchUntilPaused=false;
  r.frozenBeforeDestroy=false;
  if (setState) {
    if (DEBUG_STATES)     Slog.v(TAG_STATES,"String_Node_Str" + r + "String_Node_Str");
    r.state=ActivityState.DESTROYED;
    if (DEBUG_APP)     Slog.v(TAG_APP,"String_Node_Str" + r);
    r.app=null;
  }
  mStackSupervisor.mFinishingActivities.remove(r);
  mStackSupervisor.mWaitingVisibleActivities.remove(r);
  if (r.finishing && r.pendingResults != null) {
    for (    WeakReference<PendingIntentRecord> apr : r.pendingResults) {
      PendingIntentRecord rec=apr.get();
      if (rec != null) {
        mService.cancelIntentSenderLocked(rec,false);
      }
    }
    r.pendingResults=null;
  }
  if (cleanServices) {
    cleanUpActivityServicesLocked(r);
  }
  removeTimeoutsForActivityLocked(r);
  if (getVisibleBehindActivity() == r) {
    mStackSupervisor.requestVisibleBehindLocked(r,false);
  }
}
Program: 193041
Project: 193041
Buggy source:
final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove){
  ArrayList<ActivityRecord> stops=null;
  final boolean nowVisible=allResumedActivitiesVisible();
  for (int activityNdx=mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) {
    ActivityRecord s=mStoppingActivities.get(activityNdx);
    final boolean waitingVisible=mWaitingVisibleActivities.contains(s);
    if (DEBUG_ALL)     Slog.v(TAG,"String_Node_Str" + s + "String_Node_Str"+ nowVisible+ "String_Node_Str"+ waitingVisible+ "String_Node_Str"+ s.finishing);
    if (waitingVisible && nowVisible) {
      mWaitingVisibleActivities.remove(s);
      if (s.finishing) {
        if (DEBUG_ALL)         Slog.v(TAG,"String_Node_Str" + s);
        mWindowManager.setAppVisibility(s.appToken,false);
      }
    }
    if ((!waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
      if (DEBUG_ALL)       Slog.v(TAG,"String_Node_Str" + s);
      if (stops == null) {
        stops=new ArrayList<>();
      }
      stops.add(s);
      mStoppingActivities.remove(activityNdx);
    }
  }
  return stops;
}

Fixed version (ground truth):
final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove){
  ArrayList<ActivityRecord> stops=null;
  final boolean nowVisible=allResumedActivitiesVisible();
  for (int activityNdx=mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) {
    ActivityRecord s=mStoppingActivities.get(activityNdx);
    final boolean waitingVisible=mWaitingVisibleActivities.contains(s);
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + s + "String_Node_Str"+ nowVisible+ "String_Node_Str"+ waitingVisible+ "String_Node_Str"+ s.finishing);
    if (waitingVisible && nowVisible) {
      mWaitingVisibleActivities.remove(s);
      if (s.finishing) {
        if (DEBUG_STATES)         Slog.v(TAG,"String_Node_Str" + s);
        mWindowManager.setAppVisibility(s.appToken,false);
      }
    }
    if ((!waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
      if (DEBUG_STATES)       Slog.v(TAG,"String_Node_Str" + s);
      if (stops == null) {
        stops=new ArrayList<>();
      }
      stops.add(s);
      mStoppingActivities.remove(activityNdx);
    }
  }
  return stops;
}
Program: 193042
Project: 193042
Buggy source:
@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  final DocumentInfo cwd=getCurrentDirectory();
  final MenuItem createDir=menu.findItem(R.id.menu_create_dir);
  final MenuItem grid=menu.findItem(R.id.menu_grid);
  final MenuItem list=menu.findItem(R.id.menu_list);
  final MenuItem fileSize=menu.findItem(R.id.menu_file_size);
  final MenuItem settings=menu.findItem(R.id.menu_settings);
  boolean recents=cwd == null;
  boolean picking=mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION;
  createDir.setVisible(picking && !recents && cwd.isCreateSupported());
  mSearchManager.showMenu(!picking);
  grid.setVisible(!(picking && recents));
  list.setVisible(!(picking && recents));
  fileSize.setVisible(fileSize.isVisible() && !picking);
  settings.setVisible(false);
  if (mState.action == ACTION_CREATE) {
    final FragmentManager fm=getFragmentManager();
    SaveFragment.get(fm).prepareForDirectory(cwd);
  }
  Menus.disableHiddenItems(menu);
  return true;
}

Fixed version (ground truth):
@Override public boolean onPrepareOptionsMenu(Menu menu){
  super.onPrepareOptionsMenu(menu);
  final DocumentInfo cwd=getCurrentDirectory();
  final MenuItem createDir=menu.findItem(R.id.menu_create_dir);
  final MenuItem grid=menu.findItem(R.id.menu_grid);
  final MenuItem list=menu.findItem(R.id.menu_list);
  final MenuItem fileSize=menu.findItem(R.id.menu_file_size);
  final MenuItem settings=menu.findItem(R.id.menu_settings);
  boolean recents=cwd == null;
  boolean picking=mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION;
  createDir.setVisible(picking && !recents && cwd.isCreateSupported());
  mSearchManager.showMenu(!picking);
  if (picking && recents) {
    grid.setVisible(false);
    list.setVisible(false);
  }
  fileSize.setVisible(fileSize.isVisible() && !picking);
  settings.setVisible(false);
  if (mState.action == ACTION_CREATE) {
    final FragmentManager fm=getFragmentManager();
    SaveFragment.get(fm).prepareForDirectory(cwd);
  }
  Menus.disableHiddenItems(menu);
  return true;
}
Program: 193043
Project: 193043
Buggy source:
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
}

Fixed version (ground truth):
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime);
}
Program: 193044
Project: 193044
Buggy source:
long getBeginIdleTime(String packageName){
  final IntervalStats yearly=mCurrentStats[UsageStatsManager.INTERVAL_YEARLY];
  UsageStats packageUsage;
  if ((packageUsage=yearly.packageStats.get(packageName)) == null) {
    return -1;
  }
 else {
    return packageUsage.getBeginIdleTime();
  }
}

Fixed version (ground truth):
long getBeginIdleTime(String packageName){
  UsageStats packageUsage;
  if ((packageUsage=mAppIdleRollingWindow.packageStats.get(packageName)) == null) {
    return -1;
  }
 else {
    return packageUsage.getBeginIdleTime();
  }
}
Program: 193045
Project: 193045
Buggy source:
void dump(IndentingPrintWriter pw,final long screenOnTime){
  for (int interval=0; interval < mCurrentStats.length; interval++) {
    pw.print("String_Node_Str");
    pw.print(intervalToString(interval));
    pw.println("String_Node_Str");
    printIntervalStats(pw,mCurrentStats[interval],screenOnTime,true);
  }
}

Fixed version (ground truth):
void dump(IndentingPrintWriter pw,final long screenOnTime){
  for (int interval=0; interval < mCurrentStats.length; interval++) {
    pw.print("String_Node_Str");
    pw.print(intervalToString(interval));
    pw.println("String_Node_Str");
    printIntervalStats(pw,mCurrentStats[interval],screenOnTime,true);
  }
  pw.println("String_Node_Str");
  printIntervalStats(pw,mAppIdleRollingWindow,screenOnTime,true);
}
Program: 193046
Project: 193046
Buggy source:
void setSystemLastUsedTime(String packageName,long lastUsedTime){
  for (  IntervalStats stats : mCurrentStats) {
    stats.updateSystemLastUsedTime(packageName,lastUsedTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void setSystemLastUsedTime(String packageName,long lastUsedTime){
  for (  IntervalStats stats : mCurrentStats) {
    stats.updateSystemLastUsedTime(packageName,lastUsedTime);
  }
  mAppIdleRollingWindow.updateSystemLastUsedTime(packageName,lastUsedTime);
  notifyStatsChanged();
}
Program: 193047
Project: 193047
Buggy source:
@Override public void combine(IntervalStats stats,boolean mutable,List<UsageEvents.Event> accumulatedResult){
  if (stats.events == null) {
    return;
  }
  final int startIndex=stats.events.closestIndexOnOrAfter(beginTime);
  if (startIndex < 0) {
    return;
  }
  final int size=stats.events.size();
  for (int i=startIndex; i < size; i++) {
    if (stats.events.keyAt(i) >= endTime) {
      return;
    }
    final UsageEvents.Event event=stats.events.valueAt(i);
    names.add(event.mPackage);
    if (event.mClass != null) {
      names.add(event.mClass);
    }
    accumulatedResult.add(event);
  }
}

Fixed version (ground truth):
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats);
}
Program: 193048
Project: 193048
Buggy source:
void init(final long currentTimeMillis,final long deviceUsageTime){
  mDatabase.init(currentTimeMillis);
  int nullCount=0;
  for (int i=0; i < mCurrentStats.length; i++) {
    mCurrentStats[i]=mDatabase.getLatestUsageStats(i);
    if (mCurrentStats[i] == null) {
      nullCount++;
    }
  }
  if (nullCount > 0) {
    if (nullCount != mCurrentStats.length) {
      Slog.w(TAG,mLogPrefix + "String_Node_Str");
    }
 else {
    }
    loadActiveStats(currentTimeMillis,false,false);
  }
 else {
    mDailyExpiryDate.setTimeInMillis(mCurrentStats[UsageStatsManager.INTERVAL_DAILY].beginTime);
    mDailyExpiryDate.addDays(1);
    mDailyExpiryDate.truncateToDay();
    Slog.i(TAG,mLogPrefix + "String_Node_Str" + sDateFormat.format(mDailyExpiryDate.getTimeInMillis())+ "String_Node_Str"+ mDailyExpiryDate.getTimeInMillis()+ "String_Node_Str");
  }
  for (  IntervalStats stat : mCurrentStats) {
    final int pkgCount=stat.packageStats.size();
    for (int i=0; i < pkgCount; i++) {
      UsageStats pkgStats=stat.packageStats.valueAt(i);
      if (pkgStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || pkgStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
        stat.update(pkgStats.mPackageName,stat.lastTimeSaved,UsageEvents.Event.END_OF_DAY);
        notifyStatsChanged();
      }
    }
    stat.updateConfigurationStats(null,stat.lastTimeSaved);
  }
  if (mDatabase.isNewUpdate()) {
    initializeDefaultsForApps(currentTimeMillis,deviceUsageTime,mDatabase.isFirstUpdate());
  }
}

Fixed version (ground truth):
void init(final long currentTimeMillis,final long deviceUsageTime){
  mDatabase.init(currentTimeMillis);
  int nullCount=0;
  for (int i=0; i < mCurrentStats.length; i++) {
    mCurrentStats[i]=mDatabase.getLatestUsageStats(i);
    if (mCurrentStats[i] == null) {
      nullCount++;
    }
  }
  if (nullCount > 0) {
    if (nullCount != mCurrentStats.length) {
      Slog.w(TAG,mLogPrefix + "String_Node_Str");
    }
 else {
    }
    loadActiveStats(currentTimeMillis,false,false);
  }
 else {
    mDailyExpiryDate.setTimeInMillis(mCurrentStats[UsageStatsManager.INTERVAL_DAILY].beginTime);
    mDailyExpiryDate.addDays(1);
    mDailyExpiryDate.truncateToDay();
    Slog.i(TAG,mLogPrefix + "String_Node_Str" + sDateFormat.format(mDailyExpiryDate.getTimeInMillis())+ "String_Node_Str"+ mDailyExpiryDate.getTimeInMillis()+ "String_Node_Str");
  }
  for (  IntervalStats stat : mCurrentStats) {
    final int pkgCount=stat.packageStats.size();
    for (int i=0; i < pkgCount; i++) {
      UsageStats pkgStats=stat.packageStats.valueAt(i);
      if (pkgStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || pkgStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
        stat.update(pkgStats.mPackageName,stat.lastTimeSaved,UsageEvents.Event.END_OF_DAY);
        notifyStatsChanged();
      }
    }
    stat.updateConfigurationStats(null,stat.lastTimeSaved);
  }
  if (mDatabase.isNewUpdate()) {
    initializeDefaultsForApps(currentTimeMillis,deviceUsageTime,mDatabase.isFirstUpdate());
  }
  refreshAppIdleRollingWindow(currentTimeMillis);
}
Program: 193049
Project: 193049
Buggy source:
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}
Program: 193050
Project: 193050
Buggy source:
long getSystemLastUsedTime(String packageName){
  final IntervalStats yearly=mCurrentStats[UsageStatsManager.INTERVAL_YEARLY];
  UsageStats packageUsage;
  if ((packageUsage=yearly.packageStats.get(packageName)) == null) {
    return -1;
  }
 else {
    return packageUsage.getLastTimeSystemUsed();
  }
}

Fixed version (ground truth):
long getSystemLastUsedTime(String packageName){
  UsageStats packageUsage;
  if ((packageUsage=mAppIdleRollingWindow.packageStats.get(packageName)) == null) {
    return -1;
  }
 else {
    return packageUsage.getLastTimeSystemUsed();
  }
}
Program: 193051
Project: 193051
Buggy source:
/** 
 * Sets the beginIdleTime for each of the intervals.
 * @param beginIdleTime
 */
void setBeginIdleTime(String packageName,long beginIdleTime){
  for (  IntervalStats stats : mCurrentStats) {
    stats.updateBeginIdleTime(packageName,beginIdleTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
/** 
 * Sets the beginIdleTime for each of the intervals.
 * @param beginIdleTime
 */
void setBeginIdleTime(String packageName,long beginIdleTime){
  for (  IntervalStats stats : mCurrentStats) {
    stats.updateBeginIdleTime(packageName,beginIdleTime);
  }
  mAppIdleRollingWindow.updateBeginIdleTime(packageName,beginIdleTime);
  notifyStatsChanged();
}
Program: 193053
Project: 193053
Buggy source:
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
}

Fixed version (ground truth):
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime);
}
Program: 193054
Project: 193054
Buggy source:
long getBeginIdleTime(String packageName){
  final IntervalStats yearly=mCurrentStats[UsageStatsManager.INTERVAL_YEARLY];
  UsageStats packageUsage;
  if ((packageUsage=yearly.packageStats.get(packageName)) == null) {
    return -1;
  }
 else {
    return packageUsage.getBeginIdleTime();
  }
}

Fixed version (ground truth):
long getBeginIdleTime(String packageName){
  UsageStats packageUsage;
  if ((packageUsage=mAppIdleRollingWindow.packageStats.get(packageName)) == null) {
    return -1;
  }
 else {
    return packageUsage.getBeginIdleTime();
  }
}
Program: 193055
Project: 193055
Buggy source:
void dump(IndentingPrintWriter pw,final long screenOnTime){
  for (int interval=0; interval < mCurrentStats.length; interval++) {
    pw.print("String_Node_Str");
    pw.print(intervalToString(interval));
    pw.println("String_Node_Str");
    printIntervalStats(pw,mCurrentStats[interval],screenOnTime,true);
  }
}

Fixed version (ground truth):
void dump(IndentingPrintWriter pw,final long screenOnTime){
  for (int interval=0; interval < mCurrentStats.length; interval++) {
    pw.print("String_Node_Str");
    pw.print(intervalToString(interval));
    pw.println("String_Node_Str");
    printIntervalStats(pw,mCurrentStats[interval],screenOnTime,true);
  }
  pw.println("String_Node_Str");
  printIntervalStats(pw,mAppIdleRollingWindow,screenOnTime,true);
}
Program: 193056
Project: 193056
Buggy source:
void setSystemLastUsedTime(String packageName,long lastUsedTime){
  for (  IntervalStats stats : mCurrentStats) {
    stats.updateSystemLastUsedTime(packageName,lastUsedTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void setSystemLastUsedTime(String packageName,long lastUsedTime){
  for (  IntervalStats stats : mCurrentStats) {
    stats.updateSystemLastUsedTime(packageName,lastUsedTime);
  }
  mAppIdleRollingWindow.updateSystemLastUsedTime(packageName,lastUsedTime);
  notifyStatsChanged();
}
Program: 193057
Project: 193057
Buggy source:
@Override public void combine(IntervalStats stats,boolean mutable,List<UsageEvents.Event> accumulatedResult){
  if (stats.events == null) {
    return;
  }
  final int startIndex=stats.events.closestIndexOnOrAfter(beginTime);
  if (startIndex < 0) {
    return;
  }
  final int size=stats.events.size();
  for (int i=startIndex; i < size; i++) {
    if (stats.events.keyAt(i) >= endTime) {
      return;
    }
    final UsageEvents.Event event=stats.events.valueAt(i);
    names.add(event.mPackage);
    if (event.mClass != null) {
      names.add(event.mClass);
    }
    accumulatedResult.add(event);
  }
}

Fixed version (ground truth):
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats);
}
Program: 193058
Project: 193058
Buggy source:
void init(final long currentTimeMillis,final long deviceUsageTime){
  mDatabase.init(currentTimeMillis);
  int nullCount=0;
  for (int i=0; i < mCurrentStats.length; i++) {
    mCurrentStats[i]=mDatabase.getLatestUsageStats(i);
    if (mCurrentStats[i] == null) {
      nullCount++;
    }
  }
  if (nullCount > 0) {
    if (nullCount != mCurrentStats.length) {
      Slog.w(TAG,mLogPrefix + "String_Node_Str");
    }
 else {
    }
    loadActiveStats(currentTimeMillis,false,false);
  }
 else {
    mDailyExpiryDate.setTimeInMillis(mCurrentStats[UsageStatsManager.INTERVAL_DAILY].beginTime);
    mDailyExpiryDate.addDays(1);
    mDailyExpiryDate.truncateToDay();
    Slog.i(TAG,mLogPrefix + "String_Node_Str" + sDateFormat.format(mDailyExpiryDate.getTimeInMillis())+ "String_Node_Str"+ mDailyExpiryDate.getTimeInMillis()+ "String_Node_Str");
  }
  for (  IntervalStats stat : mCurrentStats) {
    final int pkgCount=stat.packageStats.size();
    for (int i=0; i < pkgCount; i++) {
      UsageStats pkgStats=stat.packageStats.valueAt(i);
      if (pkgStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || pkgStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
        stat.update(pkgStats.mPackageName,stat.lastTimeSaved,UsageEvents.Event.END_OF_DAY);
        notifyStatsChanged();
      }
    }
    stat.updateConfigurationStats(null,stat.lastTimeSaved);
  }
  if (mDatabase.isNewUpdate()) {
    initializeDefaultsForApps(currentTimeMillis,deviceUsageTime,mDatabase.isFirstUpdate());
  }
}

Fixed version (ground truth):
void init(final long currentTimeMillis,final long deviceUsageTime){
  mDatabase.init(currentTimeMillis);
  int nullCount=0;
  for (int i=0; i < mCurrentStats.length; i++) {
    mCurrentStats[i]=mDatabase.getLatestUsageStats(i);
    if (mCurrentStats[i] == null) {
      nullCount++;
    }
  }
  if (nullCount > 0) {
    if (nullCount != mCurrentStats.length) {
      Slog.w(TAG,mLogPrefix + "String_Node_Str");
    }
 else {
    }
    loadActiveStats(currentTimeMillis,false,false);
  }
 else {
    mDailyExpiryDate.setTimeInMillis(mCurrentStats[UsageStatsManager.INTERVAL_DAILY].beginTime);
    mDailyExpiryDate.addDays(1);
    mDailyExpiryDate.truncateToDay();
    Slog.i(TAG,mLogPrefix + "String_Node_Str" + sDateFormat.format(mDailyExpiryDate.getTimeInMillis())+ "String_Node_Str"+ mDailyExpiryDate.getTimeInMillis()+ "String_Node_Str");
  }
  for (  IntervalStats stat : mCurrentStats) {
    final int pkgCount=stat.packageStats.size();
    for (int i=0; i < pkgCount; i++) {
      UsageStats pkgStats=stat.packageStats.valueAt(i);
      if (pkgStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || pkgStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
        stat.update(pkgStats.mPackageName,stat.lastTimeSaved,UsageEvents.Event.END_OF_DAY);
        notifyStatsChanged();
      }
    }
    stat.updateConfigurationStats(null,stat.lastTimeSaved);
  }
  if (mDatabase.isNewUpdate()) {
    initializeDefaultsForApps(currentTimeMillis,deviceUsageTime,mDatabase.isFirstUpdate());
  }
  refreshAppIdleRollingWindow(currentTimeMillis);
}