Program: 180793
Project: 180793
Buggy source:
@Override public void handleMessage(Message msg){
  handleRebuildList();
switch (msg.what) {
case MSG_REBUILD_LIST:
{
    }
  break;
case MSG_LOAD_ENTRIES:
{
  int numDone=0;
synchronized (mEntriesMap) {
    for (int i=0; i < mApplications.size() && numDone < 6; i++) {
      if (!mRunning) {
        mRunning=true;
        Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,1);
        mMainHandler.sendMessage(m);
      }
      ApplicationInfo info=mApplications.get(i);
      if (mEntriesMap.get(info.packageName) == null) {
        numDone++;
        getEntryLocked(info);
      }
    }
  }
  if (numDone >= 6) {
    sendEmptyMessage(MSG_LOAD_ENTRIES);
  }
 else {
    sendEmptyMessage(MSG_LOAD_ICONS);
  }
}
break;
case MSG_LOAD_ICONS:
{
int numDone=0;
synchronized (mEntriesMap) {
for (int i=0; i < mAppEntries.size() && numDone < 2; i++) {
  AppEntry entry=mAppEntries.get(i);
  if (entry.icon == null || !entry.mounted) {
synchronized (entry) {
      if (entry.ensureIconLocked(mContext,mPm)) {
        if (!mRunning) {
          mRunning=true;
          Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,1);
          mMainHandler.sendMessage(m);
        }
        numDone++;
      }
    }
  }
}
}
if (numDone > 0) {
if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_ICON_CHANGED)) {
  mMainHandler.sendEmptyMessage(MainHandler.MSG_PACKAGE_ICON_CHANGED);
}
}
if (numDone >= 2) {
sendEmptyMessage(MSG_LOAD_ICONS);
}
 else {
sendEmptyMessage(MSG_LOAD_SIZES);
}
}
break;
case MSG_LOAD_SIZES:
{
synchronized (mEntriesMap) {
if (mCurComputingSizePkg != null) {
return;
}
long now=SystemClock.uptimeMillis();
for (int i=0; i < mAppEntries.size(); i++) {
AppEntry entry=mAppEntries.get(i);
if (entry.size == SIZE_UNKNOWN || entry.sizeStale) {
if (entry.sizeLoadStart == 0 || (entry.sizeLoadStart < (now - 20 * 1000))) {
  if (!mRunning) {
    mRunning=true;
    Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,1);
    mMainHandler.sendMessage(m);
  }
  entry.sizeLoadStart=now;
  mCurComputingSizePkg=entry.info.packageName;
  mPm.getPackageSizeInfo(mCurComputingSizePkg,mStatsObserver);
}
return;
}
}
if (!mMainHandler.hasMessages(MainHandler.MSG_ALL_SIZES_COMPUTED)) {
mMainHandler.sendEmptyMessage(MainHandler.MSG_ALL_SIZES_COMPUTED);
mRunning=false;
Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,0);
mMainHandler.sendMessage(m);
}
}
}
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
  handleRebuildList();
switch (msg.what) {
case MSG_REBUILD_LIST:
{
    }
  break;
case MSG_LOAD_ENTRIES:
{
  int numDone=0;
synchronized (mEntriesMap) {
    if (DEBUG_LOCKING)     Log.v(TAG,"String_Node_Str");
    for (int i=0; i < mApplications.size() && numDone < 6; i++) {
      if (!mRunning) {
        mRunning=true;
        Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,1);
        mMainHandler.sendMessage(m);
      }
      ApplicationInfo info=mApplications.get(i);
      if (mEntriesMap.get(info.packageName) == null) {
        numDone++;
        getEntryLocked(info);
      }
    }
    if (DEBUG_LOCKING)     Log.v(TAG,"String_Node_Str");
  }
  if (numDone >= 6) {
    sendEmptyMessage(MSG_LOAD_ENTRIES);
  }
 else {
    sendEmptyMessage(MSG_LOAD_ICONS);
  }
}
break;
case MSG_LOAD_ICONS:
{
int numDone=0;
synchronized (mEntriesMap) {
if (DEBUG_LOCKING) Log.v(TAG,"String_Node_Str");
for (int i=0; i < mAppEntries.size() && numDone < 2; i++) {
  AppEntry entry=mAppEntries.get(i);
  if (entry.icon == null || !entry.mounted) {
synchronized (entry) {
      if (entry.ensureIconLocked(mContext,mPm)) {
        if (!mRunning) {
          mRunning=true;
          Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,1);
          mMainHandler.sendMessage(m);
        }
        numDone++;
      }
    }
  }
}
if (DEBUG_LOCKING) Log.v(TAG,"String_Node_Str");
}
if (numDone > 0) {
if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_ICON_CHANGED)) {
  mMainHandler.sendEmptyMessage(MainHandler.MSG_PACKAGE_ICON_CHANGED);
}
}
if (numDone >= 2) {
sendEmptyMessage(MSG_LOAD_ICONS);
}
 else {
sendEmptyMessage(MSG_LOAD_SIZES);
}
}
break;
case MSG_LOAD_SIZES:
{
synchronized (mEntriesMap) {
if (DEBUG_LOCKING) Log.v(TAG,"String_Node_Str");
if (mCurComputingSizePkg != null) {
if (DEBUG_LOCKING) Log.v(TAG,"String_Node_Str");
return;
}
long now=SystemClock.uptimeMillis();
for (int i=0; i < mAppEntries.size(); i++) {
AppEntry entry=mAppEntries.get(i);
if (entry.size == SIZE_UNKNOWN || entry.sizeStale) {
if (entry.sizeLoadStart == 0 || (entry.sizeLoadStart < (now - 20 * 1000))) {
  if (!mRunning) {
    mRunning=true;
    Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,1);
    mMainHandler.sendMessage(m);
  }
  entry.sizeLoadStart=now;
  mCurComputingSizePkg=entry.info.packageName;
  mPm.getPackageSizeInfo(mCurComputingSizePkg,mStatsObserver);
}
if (DEBUG_LOCKING) Log.v(TAG,"String_Node_Str");
return;
}
}
if (!mMainHandler.hasMessages(MainHandler.MSG_ALL_SIZES_COMPUTED)) {
mMainHandler.sendEmptyMessage(MainHandler.MSG_ALL_SIZES_COMPUTED);
mRunning=false;
Message m=mMainHandler.obtainMessage(MainHandler.MSG_RUNNING_STATE_CHANGED,0);
mMainHandler.sendMessage(m);
}
if (DEBUG_LOCKING) Log.v(TAG,"String_Node_Str");
}
}
break;
}
}