Program: 2461
Project: 2461
Buggy source:
boolean readLPw(PackageManagerService service,List<UserInfo> users,int sdkVersion,boolean onlyCore){
  FileInputStream str=null;
  if (mBackupSettingsFilename.exists()) {
    try {
      str=new FileInputStream(mBackupSettingsFilename);
      mReadMessages.append("String_Node_Str");
      PackageManagerService.reportSettingsProblem(Log.INFO,"String_Node_Str");
      if (mSettingsFilename.exists()) {
        Slog.w(PackageManagerService.TAG,"String_Node_Str" + mSettingsFilename);
        mSettingsFilename.delete();
      }
    }
 catch (    java.io.IOException e) {
    }
  }
  mPendingPackages.clear();
  mPastSignatures.clear();
  try {
    if (str == null) {
      if (!mSettingsFilename.exists()) {
        mReadMessages.append("String_Node_Str");
        PackageManagerService.reportSettingsProblem(Log.INFO,"String_Node_Str");
        if (!onlyCore) {
          readDefaultPreferredAppsLPw(service,0);
        }
        mInternalSdkPlatform=mExternalSdkPlatform=sdkVersion;
        return false;
      }
      str=new FileInputStream(mSettingsFilename);
    }
    XmlPullParser parser=Xml.newPullParser();
    parser.setInput(str,null);
    int type;
    while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
      ;
    }
    if (type != XmlPullParser.START_TAG) {
      mReadMessages.append("String_Node_Str");
      PackageManagerService.reportSettingsProblem(Log.WARN,"String_Node_Str");
      Log.wtf(PackageManagerService.TAG,"String_Node_Str");
      return false;
    }
    int outerDepth=parser.getDepth();
    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
      if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
        continue;
      }
      String tagName=parser.getName();
      if (tagName.equals("String_Node_Str")) {
        readPackageLPw(parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readPermissionsLPw(mPermissions,parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readPermissionsLPw(mPermissionTrees,parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readSharedUserLPw(parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
      }
 else       if (tagName.equals("String_Node_Str")) {
        readPreferredActivitiesLPw(parser,0);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readDisabledSysPackageLPw(parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        String name=parser.getAttributeValue(null,ATTR_NAME);
        String userStr=parser.getAttributeValue(null,ATTR_USER);
        String codeStr=parser.getAttributeValue(null,ATTR_CODE);
        if (name != null) {
          int userId=0;
          boolean andCode=true;
          try {
            if (userStr != null) {
              userId=Integer.parseInt(userStr);
            }
          }
 catch (          NumberFormatException e) {
          }
          if (codeStr != null) {
            andCode=Boolean.parseBoolean(codeStr);
          }
          addPackageToCleanLPw(new PackageCleanItem(userId,name,andCode));
        }
      }
 else       if (tagName.equals("String_Node_Str")) {
        String nname=parser.getAttributeValue(null,"String_Node_Str");
        String oname=parser.getAttributeValue(null,"String_Node_Str");
        if (nname != null && oname != null) {
          mRenamedPackages.put(nname,oname);
        }
      }
 else       if (tagName.equals("String_Node_Str")) {
        mInternalSdkPlatform=mExternalSdkPlatform=0;
        try {
          String internal=parser.getAttributeValue(null,"String_Node_Str");
          if (internal != null) {
            mInternalSdkPlatform=Integer.parseInt(internal);
          }
          String external=parser.getAttributeValue(null,"String_Node_Str");
          if (external != null) {
            mExternalSdkPlatform=Integer.parseInt(external);
          }
        }
 catch (        NumberFormatException e) {
        }
      }
 else       if (tagName.equals("String_Node_Str")) {
        final String deviceIdentity=parser.getAttributeValue(null,"String_Node_Str");
        try {
          mVerifierDeviceIdentity=VerifierDeviceIdentity.parse(deviceIdentity);
        }
 catch (        IllegalArgumentException e) {
          Slog.w(PackageManagerService.TAG,"String_Node_Str" + e.getMessage());
        }
      }
 else       if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
        final String enforcement=parser.getAttributeValue(null,ATTR_ENFORCEMENT);
        mReadExternalStorageEnforced="String_Node_Str".equals(enforcement);
      }
 else {
        Slog.w(PackageManagerService.TAG,"String_Node_Str" + parser.getName());
        XmlUtils.skipCurrentTag(parser);
      }
    }
    str.close();
  }
 catch (  XmlPullParserException e) {
    mReadMessages.append("String_Node_Str" + e.toString());
    PackageManagerService.reportSettingsProblem(Log.ERROR,"String_Node_Str" + e);
    Log.wtf(PackageManagerService.TAG,"String_Node_Str",e);
  }
catch (  java.io.IOException e) {
    mReadMessages.append("String_Node_Str" + e.toString());
    PackageManagerService.reportSettingsProblem(Log.ERROR,"String_Node_Str" + e);
    Log.wtf(PackageManagerService.TAG,"String_Node_Str",e);
  }
  final int N=mPendingPackages.size();
  for (int i=0; i < N; i++) {
    final PendingPackage pp=mPendingPackages.get(i);
    Object idObj=getUserIdLPr(pp.sharedId);
    if (idObj != null && idObj instanceof SharedUserSetting) {
      PackageSetting p=getPackageLPw(pp.name,null,pp.realName,(SharedUserSetting)idObj,pp.codePath,pp.resourcePath,pp.nativeLibraryPathString,pp.versionCode,pp.pkgFlags,null,true,false);
      if (p == null) {
        PackageManagerService.reportSettingsProblem(Log.WARN,"String_Node_Str" + pp.name);
        continue;
      }
      p.copyFrom(pp);
    }
 else     if (idObj != null) {
      String msg="String_Node_Str" + pp.name + "String_Node_Str"+ pp.sharedId+ "String_Node_Str";
      mReadMessages.append(msg);
      PackageManagerService.reportSettingsProblem(Log.ERROR,msg);
    }
 else {
      String msg="String_Node_Str" + pp.name + "String_Node_Str"+ pp.sharedId+ "String_Node_Str";
      mReadMessages.append(msg);
      PackageManagerService.reportSettingsProblem(Log.ERROR,msg);
    }
  }
  mPendingPackages.clear();
  if (mBackupStoppedPackagesFilename.exists() || mStoppedPackagesFilename.exists()) {
    readStoppedLPw();
    mBackupStoppedPackagesFilename.delete();
    mStoppedPackagesFilename.delete();
    writePackageRestrictionsLPr(0);
  }
 else {
    if (users == null) {
      readPackageRestrictionsLPr(0);
    }
 else {
      for (      UserInfo user : users) {
        readPackageRestrictionsLPr(user.id);
      }
    }
  }
  final Iterator<PackageSetting> disabledIt=mDisabledSysPackages.values().iterator();
  while (disabledIt.hasNext()) {
    final PackageSetting disabledPs=disabledIt.next();
    final Object id=getUserIdLPr(disabledPs.appId);
    if (id != null && id instanceof SharedUserSetting) {
      disabledPs.sharedUser=(SharedUserSetting)id;
    }
  }
  mReadMessages.append("String_Node_Str" + mPackages.size() + "String_Node_Str"+ mSharedUsers.size()+ "String_Node_Str");
  return true;
}

Fixed version (ground truth):
boolean readLPw(PackageManagerService service,List<UserInfo> users,int sdkVersion,boolean onlyCore){
  FileInputStream str=null;
  if (mBackupSettingsFilename.exists()) {
    try {
      str=new FileInputStream(mBackupSettingsFilename);
      mReadMessages.append("String_Node_Str");
      PackageManagerService.reportSettingsProblem(Log.INFO,"String_Node_Str");
      if (mSettingsFilename.exists()) {
        Slog.w(PackageManagerService.TAG,"String_Node_Str" + mSettingsFilename);
        mSettingsFilename.delete();
      }
    }
 catch (    java.io.IOException e) {
    }
  }
  mPendingPackages.clear();
  mPastSignatures.clear();
  try {
    if (str == null) {
      if (!mSettingsFilename.exists()) {
        mReadMessages.append("String_Node_Str");
        PackageManagerService.reportSettingsProblem(Log.INFO,"String_Node_Str");
        mInternalSdkPlatform=mExternalSdkPlatform=sdkVersion;
        return false;
      }
      str=new FileInputStream(mSettingsFilename);
    }
    XmlPullParser parser=Xml.newPullParser();
    parser.setInput(str,null);
    int type;
    while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
      ;
    }
    if (type != XmlPullParser.START_TAG) {
      mReadMessages.append("String_Node_Str");
      PackageManagerService.reportSettingsProblem(Log.WARN,"String_Node_Str");
      Log.wtf(PackageManagerService.TAG,"String_Node_Str");
      return false;
    }
    int outerDepth=parser.getDepth();
    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
      if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
        continue;
      }
      String tagName=parser.getName();
      if (tagName.equals("String_Node_Str")) {
        readPackageLPw(parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readPermissionsLPw(mPermissions,parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readPermissionsLPw(mPermissionTrees,parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readSharedUserLPw(parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
      }
 else       if (tagName.equals("String_Node_Str")) {
        readPreferredActivitiesLPw(parser,0);
      }
 else       if (tagName.equals("String_Node_Str")) {
        readDisabledSysPackageLPw(parser);
      }
 else       if (tagName.equals("String_Node_Str")) {
        String name=parser.getAttributeValue(null,ATTR_NAME);
        String userStr=parser.getAttributeValue(null,ATTR_USER);
        String codeStr=parser.getAttributeValue(null,ATTR_CODE);
        if (name != null) {
          int userId=0;
          boolean andCode=true;
          try {
            if (userStr != null) {
              userId=Integer.parseInt(userStr);
            }
          }
 catch (          NumberFormatException e) {
          }
          if (codeStr != null) {
            andCode=Boolean.parseBoolean(codeStr);
          }
          addPackageToCleanLPw(new PackageCleanItem(userId,name,andCode));
        }
      }
 else       if (tagName.equals("String_Node_Str")) {
        String nname=parser.getAttributeValue(null,"String_Node_Str");
        String oname=parser.getAttributeValue(null,"String_Node_Str");
        if (nname != null && oname != null) {
          mRenamedPackages.put(nname,oname);
        }
      }
 else       if (tagName.equals("String_Node_Str")) {
        mInternalSdkPlatform=mExternalSdkPlatform=0;
        try {
          String internal=parser.getAttributeValue(null,"String_Node_Str");
          if (internal != null) {
            mInternalSdkPlatform=Integer.parseInt(internal);
          }
          String external=parser.getAttributeValue(null,"String_Node_Str");
          if (external != null) {
            mExternalSdkPlatform=Integer.parseInt(external);
          }
        }
 catch (        NumberFormatException e) {
        }
      }
 else       if (tagName.equals("String_Node_Str")) {
        final String deviceIdentity=parser.getAttributeValue(null,"String_Node_Str");
        try {
          mVerifierDeviceIdentity=VerifierDeviceIdentity.parse(deviceIdentity);
        }
 catch (        IllegalArgumentException e) {
          Slog.w(PackageManagerService.TAG,"String_Node_Str" + e.getMessage());
        }
      }
 else       if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
        final String enforcement=parser.getAttributeValue(null,ATTR_ENFORCEMENT);
        mReadExternalStorageEnforced="String_Node_Str".equals(enforcement);
      }
 else {
        Slog.w(PackageManagerService.TAG,"String_Node_Str" + parser.getName());
        XmlUtils.skipCurrentTag(parser);
      }
    }
    str.close();
  }
 catch (  XmlPullParserException e) {
    mReadMessages.append("String_Node_Str" + e.toString());
    PackageManagerService.reportSettingsProblem(Log.ERROR,"String_Node_Str" + e);
    Log.wtf(PackageManagerService.TAG,"String_Node_Str",e);
  }
catch (  java.io.IOException e) {
    mReadMessages.append("String_Node_Str" + e.toString());
    PackageManagerService.reportSettingsProblem(Log.ERROR,"String_Node_Str" + e);
    Log.wtf(PackageManagerService.TAG,"String_Node_Str",e);
  }
  final int N=mPendingPackages.size();
  for (int i=0; i < N; i++) {
    final PendingPackage pp=mPendingPackages.get(i);
    Object idObj=getUserIdLPr(pp.sharedId);
    if (idObj != null && idObj instanceof SharedUserSetting) {
      PackageSetting p=getPackageLPw(pp.name,null,pp.realName,(SharedUserSetting)idObj,pp.codePath,pp.resourcePath,pp.nativeLibraryPathString,pp.versionCode,pp.pkgFlags,null,true,false);
      if (p == null) {
        PackageManagerService.reportSettingsProblem(Log.WARN,"String_Node_Str" + pp.name);
        continue;
      }
      p.copyFrom(pp);
    }
 else     if (idObj != null) {
      String msg="String_Node_Str" + pp.name + "String_Node_Str"+ pp.sharedId+ "String_Node_Str";
      mReadMessages.append(msg);
      PackageManagerService.reportSettingsProblem(Log.ERROR,msg);
    }
 else {
      String msg="String_Node_Str" + pp.name + "String_Node_Str"+ pp.sharedId+ "String_Node_Str";
      mReadMessages.append(msg);
      PackageManagerService.reportSettingsProblem(Log.ERROR,msg);
    }
  }
  mPendingPackages.clear();
  if (mBackupStoppedPackagesFilename.exists() || mStoppedPackagesFilename.exists()) {
    readStoppedLPw();
    mBackupStoppedPackagesFilename.delete();
    mStoppedPackagesFilename.delete();
    writePackageRestrictionsLPr(0);
  }
 else {
    if (users == null) {
      readPackageRestrictionsLPr(0);
    }
 else {
      for (      UserInfo user : users) {
        readPackageRestrictionsLPr(user.id);
      }
    }
  }
  final Iterator<PackageSetting> disabledIt=mDisabledSysPackages.values().iterator();
  while (disabledIt.hasNext()) {
    final PackageSetting disabledPs=disabledIt.next();
    final Object id=getUserIdLPr(disabledPs.appId);
    if (id != null && id instanceof SharedUserSetting) {
      disabledPs.sharedUser=(SharedUserSetting)id;
    }
  }
  mReadMessages.append("String_Node_Str" + mPackages.size() + "String_Node_Str"+ mSharedUsers.size()+ "String_Node_Str");
  return true;
}