Program: 196526
Project: 196526
Buggy source:
private void applyDefaultPreferredActivityLPw(PackageManagerService service,Intent intent,int flags,ComponentName cn,String scheme,PatternMatcher ssp,IntentFilter.AuthorityEntry auth,PatternMatcher path,int userId){
  List<ResolveInfo> ri=service.mActivities.queryIntent(intent,intent.getType(),flags,0);
  if (PackageManagerService.DEBUG_PREFERRED)   Log.d(TAG,"String_Node_Str" + intent + "String_Node_Str"+ ri);
  int match=0;
  if (ri != null && ri.size() > 1) {
    boolean haveAct=false;
    ComponentName haveNonSys=null;
    ComponentName[] set=new ComponentName[ri.size()];
    for (int i=0; i < ri.size(); i++) {
      ActivityInfo ai=ri.get(i).activityInfo;
      set[i]=new ComponentName(ai.packageName,ai.name);
      if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        if (ri.get(i).match >= match) {
          if (PackageManagerService.DEBUG_PREFERRED)           Log.d(TAG,"String_Node_Str" + ai.packageName + "String_Node_Str"+ ai.name+ "String_Node_Str");
          haveNonSys=set[i];
          break;
        }
      }
 else       if (cn.getPackageName().equals(ai.packageName) && cn.getClassName().equals(ai.name)) {
        if (PackageManagerService.DEBUG_PREFERRED)         Log.d(TAG,"String_Node_Str" + ai.packageName + "String_Node_Str"+ ai.name+ "String_Node_Str");
        haveAct=true;
        match=ri.get(i).match;
      }
 else {
        if (PackageManagerService.DEBUG_PREFERRED)         Log.d(TAG,"String_Node_Str" + ai.packageName + "String_Node_Str"+ ai.name+ "String_Node_Str");
      }
    }
    if (haveAct && haveNonSys == null) {
      IntentFilter filter=new IntentFilter();
      if (intent.getAction() != null) {
        filter.addAction(intent.getAction());
      }
      if (intent.getCategories() != null) {
        for (        String cat : intent.getCategories()) {
          filter.addCategory(cat);
        }
      }
      if ((flags & PackageManager.MATCH_DEFAULT_ONLY) != 0) {
        filter.addCategory(Intent.CATEGORY_DEFAULT);
      }
      if (scheme != null) {
        filter.addDataScheme(scheme);
      }
      if (ssp != null) {
        filter.addDataSchemeSpecificPart(ssp.getPath(),ssp.getType());
      }
      if (auth != null) {
        filter.addDataAuthority(auth);
      }
      if (path != null) {
        filter.addDataPath(path);
      }
      if (intent.getType() != null) {
        try {
          filter.addDataType(intent.getType());
        }
 catch (        IntentFilter.MalformedMimeTypeException ex) {
          Slog.w(TAG,"String_Node_Str" + intent.getType() + "String_Node_Str"+ cn);
        }
      }
      PreferredActivity pa=new PreferredActivity(filter,match,set,cn,true);
      editPreferredActivitiesLPw(userId).addFilter(pa);
    }
 else     if (haveNonSys == null) {
      StringBuilder sb=new StringBuilder();
      sb.append("String_Node_Str");
      sb.append(cn.flattenToShortString());
      sb.append("String_Node_Str");
      sb.append(intent);
      sb.append("String_Node_Str");
      for (int i=0; i < set.length; i++) {
        if (i > 0)         sb.append("String_Node_Str");
        sb.append(set[i].flattenToShortString());
      }
      Slog.w(TAG,sb.toString());
    }
 else {
      Slog.i(TAG,"String_Node_Str" + intent + "String_Node_Str"+ haveNonSys.flattenToShortString());
    }
  }
 else {
    Slog.w(TAG,"String_Node_Str" + intent + "String_Node_Str"+ cn.flattenToShortString());
  }
}

Fixed version (ground truth):
private void applyDefaultPreferredActivityLPw(PackageManagerService service,Intent intent,int flags,ComponentName cn,String scheme,PatternMatcher ssp,IntentFilter.AuthorityEntry auth,PatternMatcher path,int userId){
  List<ResolveInfo> ri=service.mActivities.queryIntent(intent,intent.getType(),flags,0);
  if (PackageManagerService.DEBUG_PREFERRED)   Log.d(TAG,"String_Node_Str" + intent + "String_Node_Str"+ ri);
  int systemMatch=0;
  int thirdPartyMatch=0;
  if (ri != null && ri.size() > 1) {
    boolean haveAct=false;
    ComponentName haveNonSys=null;
    ComponentName[] set=new ComponentName[ri.size()];
    for (int i=0; i < ri.size(); i++) {
      ActivityInfo ai=ri.get(i).activityInfo;
      set[i]=new ComponentName(ai.packageName,ai.name);
      if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        if (ri.get(i).match >= thirdPartyMatch) {
          if (PackageManagerService.DEBUG_PREFERRED)           Log.d(TAG,"String_Node_Str" + ai.packageName + "String_Node_Str"+ ai.name+ "String_Node_Str");
          haveNonSys=set[i];
          break;
        }
      }
 else       if (cn.getPackageName().equals(ai.packageName) && cn.getClassName().equals(ai.name)) {
        if (PackageManagerService.DEBUG_PREFERRED)         Log.d(TAG,"String_Node_Str" + ai.packageName + "String_Node_Str"+ ai.name+ "String_Node_Str");
        haveAct=true;
        systemMatch=ri.get(i).match;
      }
 else {
        if (PackageManagerService.DEBUG_PREFERRED)         Log.d(TAG,"String_Node_Str" + ai.packageName + "String_Node_Str"+ ai.name+ "String_Node_Str");
      }
    }
    if (haveNonSys != null && thirdPartyMatch < systemMatch) {
      haveNonSys=null;
    }
    if (haveAct && haveNonSys == null) {
      IntentFilter filter=new IntentFilter();
      if (intent.getAction() != null) {
        filter.addAction(intent.getAction());
      }
      if (intent.getCategories() != null) {
        for (        String cat : intent.getCategories()) {
          filter.addCategory(cat);
        }
      }
      if ((flags & PackageManager.MATCH_DEFAULT_ONLY) != 0) {
        filter.addCategory(Intent.CATEGORY_DEFAULT);
      }
      if (scheme != null) {
        filter.addDataScheme(scheme);
      }
      if (ssp != null) {
        filter.addDataSchemeSpecificPart(ssp.getPath(),ssp.getType());
      }
      if (auth != null) {
        filter.addDataAuthority(auth);
      }
      if (path != null) {
        filter.addDataPath(path);
      }
      if (intent.getType() != null) {
        try {
          filter.addDataType(intent.getType());
        }
 catch (        IntentFilter.MalformedMimeTypeException ex) {
          Slog.w(TAG,"String_Node_Str" + intent.getType() + "String_Node_Str"+ cn);
        }
      }
      PreferredActivity pa=new PreferredActivity(filter,systemMatch,set,cn,true);
      editPreferredActivitiesLPw(userId).addFilter(pa);
    }
 else     if (haveNonSys == null) {
      StringBuilder sb=new StringBuilder();
      sb.append("String_Node_Str");
      sb.append(cn.flattenToShortString());
      sb.append("String_Node_Str");
      sb.append(intent);
      sb.append("String_Node_Str");
      for (int i=0; i < set.length; i++) {
        if (i > 0)         sb.append("String_Node_Str");
        sb.append(set[i].flattenToShortString());
      }
      Slog.w(TAG,sb.toString());
    }
 else {
      Slog.i(TAG,"String_Node_Str" + intent + "String_Node_Str"+ haveNonSys.flattenToShortString());
    }
  }
 else {
    Slog.w(TAG,"String_Node_Str" + intent + "String_Node_Str"+ cn.flattenToShortString());
  }
}