Program: 42163
Project: 42163
Buggy source:
void writeLP(){
  if (mSettingsFilename.exists()) {
    if (!mBackupSettingsFilename.exists()) {
      if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
        Slog.w(TAG,"String_Node_Str");
        return;
      }
    }
 else {
      Slog.w(TAG,"String_Node_Str");
    }
  }
  mPastSignatures.clear();
  try {
    FileOutputStream str=new FileOutputStream(mSettingsFilename);
    XmlSerializer serializer=new FastXmlSerializer();
    serializer.setOutput(str,"String_Node_Str");
    serializer.startDocument(null,true);
    serializer.setFeature("String_Node_Str",true);
    serializer.startTag(null,"String_Node_Str");
    serializer.startTag(null,"String_Node_Str");
    for (    BasePermission bp : mPermissionTrees.values()) {
      writePermission(serializer,bp);
    }
    serializer.endTag(null,"String_Node_Str");
    serializer.startTag(null,"String_Node_Str");
    for (    BasePermission bp : mPermissions.values()) {
      writePermission(serializer,bp);
    }
    serializer.endTag(null,"String_Node_Str");
    for (    PackageSetting pkg : mPackages.values()) {
      writePackage(serializer,pkg);
    }
    for (    PackageSetting pkg : mDisabledSysPackages.values()) {
      writeDisabledSysPackage(serializer,pkg);
    }
    serializer.startTag(null,"String_Node_Str");
    for (    PreferredActivity pa : mPreferredActivities.filterSet()) {
      serializer.startTag(null,"String_Node_Str");
      pa.writeToXml(serializer);
      serializer.endTag(null,"String_Node_Str");
    }
    serializer.endTag(null,"String_Node_Str");
    for (    SharedUserSetting usr : mSharedUsers.values()) {
      serializer.startTag(null,"String_Node_Str");
      serializer.attribute(null,"String_Node_Str",usr.name);
      serializer.attribute(null,"String_Node_Str",Integer.toString(usr.userId));
      usr.signatures.writeXml(serializer,"String_Node_Str",mPastSignatures);
      serializer.startTag(null,"String_Node_Str");
      for (      String name : usr.grantedPermissions) {
        serializer.startTag(null,"String_Node_Str");
        serializer.attribute(null,"String_Node_Str",name);
        serializer.endTag(null,"String_Node_Str");
      }
      serializer.endTag(null,"String_Node_Str");
      serializer.endTag(null,"String_Node_Str");
    }
    if (mPackagesToBeCleaned.size() > 0) {
      for (int i=0; i < mPackagesToBeCleaned.size(); i++) {
        serializer.startTag(null,"String_Node_Str");
        serializer.attribute(null,"String_Node_Str",mPackagesToBeCleaned.get(i));
        serializer.endTag(null,"String_Node_Str");
      }
    }
    if (mRenamedPackages.size() > 0) {
      for (      HashMap.Entry<String,String> e : mRenamedPackages.entrySet()) {
        serializer.startTag(null,"String_Node_Str");
        serializer.attribute(null,"String_Node_Str",e.getKey());
        serializer.attribute(null,"String_Node_Str",e.getValue());
        serializer.endTag(null,"String_Node_Str");
      }
    }
    serializer.endTag(null,"String_Node_Str");
    serializer.endDocument();
    str.flush();
    str.close();
    mBackupSettingsFilename.delete();
    FileUtils.setPermissions(mSettingsFilename.toString(),FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP| FileUtils.S_IWGRP| FileUtils.S_IROTH,-1,-1);
    File tempFile=new File(mPackageListFilename.toString() + "String_Node_Str");
    JournaledFile journal=new JournaledFile(mPackageListFilename,tempFile);
    str=new FileOutputStream(journal.chooseForWrite());
    try {
      StringBuilder sb=new StringBuilder();
      for (      PackageSetting pkg : mPackages.values()) {
        ApplicationInfo ai=pkg.pkg.applicationInfo;
        String dataPath=ai.dataDir;
        boolean isDebug=(ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        if (dataPath.indexOf("String_Node_Str") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID)         continue;
        sb.setLength(0);
        sb.append(ai.packageName);
        sb.append("String_Node_Str");
        sb.append((int)ai.uid);
        sb.append(isDebug ? "String_Node_Str" : "String_Node_Str");
        sb.append(dataPath);
        sb.append("String_Node_Str");
        str.write(sb.toString().getBytes());
      }
      str.flush();
      str.close();
      journal.commit();
    }
 catch (    Exception e) {
      journal.rollback();
    }
    FileUtils.setPermissions(mPackageListFilename.toString(),FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP| FileUtils.S_IWGRP| FileUtils.S_IROTH,-1,-1);
    return;
  }
 catch (  XmlPullParserException e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
catch (  java.io.IOException e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
  if (mSettingsFilename.exists()) {
    if (!mSettingsFilename.delete()) {
      Log.i(TAG,"String_Node_Str" + mSettingsFilename);
    }
  }
}

Fixed version (ground truth):
void writeLP(){
  if (mSettingsFilename.exists()) {
    if (!mBackupSettingsFilename.exists()) {
      if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
        Slog.w(TAG,"String_Node_Str");
        return;
      }
    }
 else {
      mSettingsFilename.delete();
      Slog.w(TAG,"String_Node_Str");
    }
  }
  mPastSignatures.clear();
  try {
    FileOutputStream str=new FileOutputStream(mSettingsFilename);
    XmlSerializer serializer=new FastXmlSerializer();
    serializer.setOutput(str,"String_Node_Str");
    serializer.startDocument(null,true);
    serializer.setFeature("String_Node_Str",true);
    serializer.startTag(null,"String_Node_Str");
    serializer.startTag(null,"String_Node_Str");
    for (    BasePermission bp : mPermissionTrees.values()) {
      writePermission(serializer,bp);
    }
    serializer.endTag(null,"String_Node_Str");
    serializer.startTag(null,"String_Node_Str");
    for (    BasePermission bp : mPermissions.values()) {
      writePermission(serializer,bp);
    }
    serializer.endTag(null,"String_Node_Str");
    for (    PackageSetting pkg : mPackages.values()) {
      writePackage(serializer,pkg);
    }
    for (    PackageSetting pkg : mDisabledSysPackages.values()) {
      writeDisabledSysPackage(serializer,pkg);
    }
    serializer.startTag(null,"String_Node_Str");
    for (    PreferredActivity pa : mPreferredActivities.filterSet()) {
      serializer.startTag(null,"String_Node_Str");
      pa.writeToXml(serializer);
      serializer.endTag(null,"String_Node_Str");
    }
    serializer.endTag(null,"String_Node_Str");
    for (    SharedUserSetting usr : mSharedUsers.values()) {
      serializer.startTag(null,"String_Node_Str");
      serializer.attribute(null,"String_Node_Str",usr.name);
      serializer.attribute(null,"String_Node_Str",Integer.toString(usr.userId));
      usr.signatures.writeXml(serializer,"String_Node_Str",mPastSignatures);
      serializer.startTag(null,"String_Node_Str");
      for (      String name : usr.grantedPermissions) {
        serializer.startTag(null,"String_Node_Str");
        serializer.attribute(null,"String_Node_Str",name);
        serializer.endTag(null,"String_Node_Str");
      }
      serializer.endTag(null,"String_Node_Str");
      serializer.endTag(null,"String_Node_Str");
    }
    if (mPackagesToBeCleaned.size() > 0) {
      for (int i=0; i < mPackagesToBeCleaned.size(); i++) {
        serializer.startTag(null,"String_Node_Str");
        serializer.attribute(null,"String_Node_Str",mPackagesToBeCleaned.get(i));
        serializer.endTag(null,"String_Node_Str");
      }
    }
    if (mRenamedPackages.size() > 0) {
      for (      HashMap.Entry<String,String> e : mRenamedPackages.entrySet()) {
        serializer.startTag(null,"String_Node_Str");
        serializer.attribute(null,"String_Node_Str",e.getKey());
        serializer.attribute(null,"String_Node_Str",e.getValue());
        serializer.endTag(null,"String_Node_Str");
      }
    }
    serializer.endTag(null,"String_Node_Str");
    serializer.endDocument();
    str.flush();
    str.close();
    mBackupSettingsFilename.delete();
    FileUtils.setPermissions(mSettingsFilename.toString(),FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP| FileUtils.S_IWGRP| FileUtils.S_IROTH,-1,-1);
    File tempFile=new File(mPackageListFilename.toString() + "String_Node_Str");
    JournaledFile journal=new JournaledFile(mPackageListFilename,tempFile);
    str=new FileOutputStream(journal.chooseForWrite());
    try {
      StringBuilder sb=new StringBuilder();
      for (      PackageSetting pkg : mPackages.values()) {
        ApplicationInfo ai=pkg.pkg.applicationInfo;
        String dataPath=ai.dataDir;
        boolean isDebug=(ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        if (dataPath.indexOf("String_Node_Str") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID)         continue;
        sb.setLength(0);
        sb.append(ai.packageName);
        sb.append("String_Node_Str");
        sb.append((int)ai.uid);
        sb.append(isDebug ? "String_Node_Str" : "String_Node_Str");
        sb.append(dataPath);
        sb.append("String_Node_Str");
        str.write(sb.toString().getBytes());
      }
      str.flush();
      str.close();
      journal.commit();
    }
 catch (    Exception e) {
      journal.rollback();
    }
    FileUtils.setPermissions(mPackageListFilename.toString(),FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP| FileUtils.S_IWGRP| FileUtils.S_IROTH,-1,-1);
    return;
  }
 catch (  XmlPullParserException e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
catch (  java.io.IOException e) {
    Slog.w(TAG,"String_Node_Str",e);
  }
  if (mSettingsFilename.exists()) {
    if (!mSettingsFilename.delete()) {
      Log.i(TAG,"String_Node_Str" + mSettingsFilename);
    }
  }
}