Program: 45438
Project: 45438
Buggy source:
/** 
 * Loads the default set of favorite packages from an xml file.
 * @param db The database to write the values into
 */
private int loadFavorites(SQLiteDatabase db){
  Intent intent=new Intent(Intent.ACTION_MAIN,null);
  intent.addCategory(Intent.CATEGORY_LAUNCHER);
  ContentValues values=new ContentValues();
  PackageManager packageManager=mContext.getPackageManager();
  int i=0;
  try {
    XmlResourceParser parser=mContext.getResources().getXml(R.xml.default_workspace);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    XmlUtils.beginDocument(parser,TAG_FAVORITES);
    final int depth=parser.getDepth();
    int type;
    while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }
      boolean added=false;
      final String name=parser.getName();
      TypedArray a=mContext.obtainStyledAttributes(attrs,R.styleable.Favorite);
      values.clear();
      values.put(LauncherSettings.Favorites.CONTAINER,LauncherSettings.Favorites.CONTAINER_DESKTOP);
      values.put(LauncherSettings.Favorites.SCREEN,a.getString(R.styleable.Favorite_screen));
      values.put(LauncherSettings.Favorites.CELLX,a.getString(R.styleable.Favorite_x));
      values.put(LauncherSettings.Favorites.CELLY,a.getString(R.styleable.Favorite_y));
      if (TAG_FAVORITE.equals(name)) {
        added=addAppShortcut(db,values,a,packageManager,intent);
      }
 else       if (TAG_SEARCH.equals(name)) {
        added=addSearchWidget(db,values);
      }
 else       if (TAG_CLOCK.equals(name)) {
        added=addClockWidget(db,values);
      }
 else       if (TAG_APPWIDGET.equals(name)) {
        added=addAppWidget(db,values,a,packageManager);
      }
 else       if (TAG_SHORTCUT.equals(name)) {
        added=addUriShortcut(db,values,a);
      }
      if (added)       i++;
      a.recycle();
    }
  }
 catch (  XmlPullParserException e) {
    Log.w(TAG,"String_Node_Str",e);
  }
catch (  IOException e) {
    Log.w(TAG,"String_Node_Str",e);
  }
  return i;
}

Fixed version (ground truth):
/** 
 * Loads the default set of favorite packages from an xml file.
 * @param db The database to write the values into
 */
private int loadFavorites(SQLiteDatabase db){
  Intent intent=new Intent(Intent.ACTION_MAIN,null);
  intent.addCategory(Intent.CATEGORY_LAUNCHER);
  ContentValues values=new ContentValues();
  PackageManager packageManager=mContext.getPackageManager();
  int i=0;
  try {
    XmlResourceParser parser=getDefaultWorkspace();
    AttributeSet attrs=Xml.asAttributeSet(parser);
    XmlUtils.beginDocument(parser,TAG_FAVORITES);
    final int depth=parser.getDepth();
    int type;
    while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }
      boolean added=false;
      final String name=parser.getName();
      TypedArray a=mContext.obtainStyledAttributes(attrs,R.styleable.Favorite);
      values.clear();
      values.put(LauncherSettings.Favorites.CONTAINER,LauncherSettings.Favorites.CONTAINER_DESKTOP);
      values.put(LauncherSettings.Favorites.SCREEN,a.getString(R.styleable.Favorite_screen));
      values.put(LauncherSettings.Favorites.CELLX,a.getString(R.styleable.Favorite_x));
      values.put(LauncherSettings.Favorites.CELLY,a.getString(R.styleable.Favorite_y));
      if (TAG_FAVORITE.equals(name)) {
        added=addAppShortcut(db,values,a,packageManager,intent);
      }
 else       if (TAG_SEARCH.equals(name)) {
        added=addSearchWidget(db,values);
      }
 else       if (TAG_CLOCK.equals(name)) {
        added=addClockWidget(db,values);
      }
 else       if (TAG_APPWIDGET.equals(name)) {
        added=addAppWidget(db,values,a,packageManager);
      }
 else       if (TAG_SHORTCUT.equals(name)) {
        added=addUriShortcut(db,values,a);
      }
      if (added)       i++;
      a.recycle();
    }
  }
 catch (  XmlPullParserException e) {
    Log.w(TAG,"String_Node_Str",e);
  }
catch (  IOException e) {
    Log.w(TAG,"String_Node_Str",e);
  }
  return i;
}