Program: 198265
Project: 198265
Buggy source:
@Override public void replacePreferredActivity(IntentFilter filter,int match,ComponentName[] set,ComponentName activity,int userId){
  if (filter.countActions() != 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (filter.countDataAuthorities() != 0 || filter.countDataPaths() != 0 || filter.countDataSchemes() > 1 || filter.countDataTypes() != 0) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  }
  final int callingUid=Binder.getCallingUid();
  enforceCrossUserPermission(callingUid,userId,true,"String_Node_Str");
synchronized (mPackages) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) != PackageManager.PERMISSION_GRANTED) {
      if (getUidTargetSdkVersionLockedLPr(callingUid) < Build.VERSION_CODES.FROYO) {
        Slog.w(TAG,"String_Node_Str" + Binder.getCallingUid());
        return;
      }
      mContext.enforceCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS,null);
    }
    PreferredIntentResolver pir=mSettings.mPreferredActivities.get(userId);
    if (pir != null) {
      ArrayList<PreferredActivity> existing=pir.findFilters(filter);
      if (existing != null && existing.size() == 1) {
        PreferredActivity cur=existing.get(0);
        if (DEBUG_PREFERRED) {
          Slog.i(TAG,"String_Node_Str");
          filter.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
          if (!cur.mPref.mAlways) {
            Slog.i(TAG,"String_Node_Str");
          }
 else {
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mMatch);
            Slog.i(TAG,"String_Node_Str" + Arrays.toString(cur.mPref.mSetComponents));
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mShortComponent);
            Slog.i(TAG,"String_Node_Str" + (match & IntentFilter.MATCH_CATEGORY_MASK));
            Slog.i(TAG,"String_Node_Str" + Arrays.toString(set));
            Slog.i(TAG,"String_Node_Str" + activity.flattenToShortString());
          }
        }
        if (cur.mPref.mAlways && cur.mPref.mComponent.equals(activity) && cur.mPref.mMatch == (match & IntentFilter.MATCH_CATEGORY_MASK) && cur.mPref.sameSet(set)) {
          if (DEBUG_PREFERRED) {
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mShortComponent + "String_Node_Str"+ userId+ "String_Node_Str");
            filter.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
          }
 else {
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mShortComponent + "String_Node_Str"+ userId);
          }
          return;
        }
      }
      if (DEBUG_PREFERRED) {
        Slog.i(TAG,existing.size() + "String_Node_Str");
        filter.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
      }
      for (int i=0; i < existing.size(); i++) {
        PreferredActivity pa=existing.get(i);
        if (DEBUG_PREFERRED) {
          Slog.i(TAG,"String_Node_Str" + pa.mPref.mComponent + "String_Node_Str");
          pa.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
        }
        pir.removeFilter(pa);
      }
    }
    addPreferredActivityInternal(filter,match,set,activity,true,userId,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void replacePreferredActivity(IntentFilter filter,int match,ComponentName[] set,ComponentName activity,int userId){
  if (filter.countActions() != 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (filter.countDataAuthorities() != 0 || filter.countDataPaths() != 0 || filter.countDataSchemes() > 1 || filter.countDataTypes() != 0) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  }
  final int callingUid=Binder.getCallingUid();
  enforceCrossUserPermission(callingUid,userId,true,"String_Node_Str");
synchronized (mPackages) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) != PackageManager.PERMISSION_GRANTED) {
      if (getUidTargetSdkVersionLockedLPr(callingUid) < Build.VERSION_CODES.FROYO) {
        Slog.w(TAG,"String_Node_Str" + Binder.getCallingUid());
        return;
      }
      mContext.enforceCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS,null);
    }
    PreferredIntentResolver pir=mSettings.mPreferredActivities.get(userId);
    if (pir != null) {
      ArrayList<PreferredActivity> existing=pir.findFilters(filter);
      if (existing != null && existing.size() == 1) {
        PreferredActivity cur=existing.get(0);
        if (DEBUG_PREFERRED) {
          Slog.i(TAG,"String_Node_Str");
          filter.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
          if (!cur.mPref.mAlways) {
            Slog.i(TAG,"String_Node_Str");
          }
 else {
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mMatch);
            Slog.i(TAG,"String_Node_Str" + Arrays.toString(cur.mPref.mSetComponents));
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mShortComponent);
            Slog.i(TAG,"String_Node_Str" + (match & IntentFilter.MATCH_CATEGORY_MASK));
            Slog.i(TAG,"String_Node_Str" + Arrays.toString(set));
            Slog.i(TAG,"String_Node_Str" + activity.flattenToShortString());
          }
        }
        if (cur.mPref.mAlways && cur.mPref.mComponent.equals(activity) && cur.mPref.mMatch == (match & IntentFilter.MATCH_CATEGORY_MASK) && cur.mPref.sameSet(set)) {
          if (DEBUG_PREFERRED) {
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mShortComponent + "String_Node_Str"+ userId+ "String_Node_Str");
            filter.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
          }
 else {
            Slog.i(TAG,"String_Node_Str" + cur.mPref.mShortComponent + "String_Node_Str"+ userId);
          }
          return;
        }
      }
      if (existing != null) {
        if (DEBUG_PREFERRED) {
          Slog.i(TAG,existing.size() + "String_Node_Str");
          filter.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
        }
        for (int i=0; i < existing.size(); i++) {
          PreferredActivity pa=existing.get(i);
          if (DEBUG_PREFERRED) {
            Slog.i(TAG,"String_Node_Str" + pa.mPref.mComponent + "String_Node_Str");
            pa.dump(new LogPrinter(Log.INFO,TAG),"String_Node_Str");
          }
          pir.removeFilter(pa);
        }
      }
    }
    addPreferredActivityInternal(filter,match,set,activity,true,userId,"String_Node_Str");
  }
}