Program: 104927
Project: 104927
Buggy source:
public TabView openUrl(final String urlAsString,long urlLoadStartTime,final boolean setAsCurrentTab,String openedFromAppName){
  Analytics.trackOpenUrl(openedFromAppName);
  if (wasUrlRecentlyLoaded(urlAsString,urlLoadStartTime) && !urlAsString.equals(mContext.getString(R.string.empty_bubble_page))) {
    Toast.makeText(mContext,R.string.duplicate_link_will_not_be_loaded,Toast.LENGTH_SHORT).show();
    return null;
  }
  URL url;
  try {
    url=new URL(urlAsString);
  }
 catch (  MalformedURLException e) {
    Toast.makeText(mContext,mContext.getString(R.string.unsupported_scheme),Toast.LENGTH_SHORT).show();
    if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
      finish();
    }
    return null;
  }
  if (Settings.get().redirectUrlToBrowser(url)) {
    Intent intent=new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(urlAsString));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    if (MainApplication.openInBrowser(mContext,intent,false)) {
      if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
        finish();
      }
      String title=String.format(mContext.getString(R.string.link_redirected),Settings.get().getDefaultBrowserLabel());
      MainApplication.saveUrlInHistory(mContext,null,urlAsString,title);
      return null;
    }
  }
  boolean showAppPicker=false;
  PackageManager packageManager=mContext.getPackageManager();
  final List<ResolveInfo> resolveInfos=Settings.get().getAppsThatHandleUrl(url.toString(),packageManager);
  ResolveInfo defaultAppResolveInfo=Settings.get().getDefaultAppForUrl(url,resolveInfos);
  if (resolveInfos != null && resolveInfos.size() > 0) {
    if (defaultAppResolveInfo != null) {
      if (handleResolveInfo(defaultAppResolveInfo,urlAsString,urlLoadStartTime)) {
        return null;
      }
    }
 else     if (resolveInfos.size() == 1) {
      if (handleResolveInfo(resolveInfos.get(0),urlAsString,urlLoadStartTime)) {
        return null;
      }
    }
 else {
      for (      ResolveInfo info : resolveInfos) {
        if (info.activityInfo.packageName.startsWith("String_Node_Str")) {
          showAppPicker=false;
          break;
        }
 else {
          showAppPicker=true;
        }
      }
    }
  }
  boolean openedFromItself=false;
  if (null != openedFromAppName && (openedFromAppName.equals(Analytics.OPENED_URL_FROM_NEW_TAB) || openedFromAppName.equals(Analytics.OPENED_URL_FROM_HISTORY))) {
    showAppPicker=true;
    openedFromItself=true;
  }
  mCanAutoDisplayLink=true;
  final TabView result=openUrlInTab(urlAsString,urlLoadStartTime,setAsCurrentTab,showAppPicker);
  if (!openedFromItself && showAppPicker && MainApplication.sShowingAppPickerDialog == false) {
    AlertDialog dialog=ActionItem.getActionItemPickerAlert(mContext,resolveInfos,R.string.pick_default_app,new ActionItem.OnActionItemDefaultSelectedListener(){
      @Override public void onSelected(      ActionItem actionItem,      boolean always){
        boolean loaded=false;
        for (        ResolveInfo resolveInfo : resolveInfos) {
          if (resolveInfo.activityInfo.packageName.equals(actionItem.mPackageName) && resolveInfo.activityInfo.name.equals(actionItem.mActivityClassName)) {
            if (always) {
              Settings.get().setDefaultApp(urlAsString,resolveInfo);
            }
            if (resolveInfo.activityInfo.packageName.equals(mAppPackageName)) {
              break;
            }
            loaded=MainApplication.loadIntent(mContext,actionItem.mPackageName,actionItem.mActivityClassName,urlAsString,-1,true);
            break;
          }
        }
        if (loaded) {
          Settings.get().addRedirectToApp(urlAsString);
          closeTab(result,contentViewShowing(),false);
          if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
            finish();
          }
          if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
            MainController.get().switchToBubbleView();
          }
        }
      }
    }
);
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener(){
      @Override public void onDismiss(      DialogInterface dialog){
        MainApplication.sShowingAppPickerDialog=false;
      }
    }
);
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    Util.showThemedDialog(dialog);
    MainApplication.sShowingAppPickerDialog=true;
  }
  return result;
}

Fixed version (ground truth):
public TabView openUrl(final String urlAsString,long urlLoadStartTime,final boolean setAsCurrentTab,String openedFromAppName){
  Analytics.trackOpenUrl(openedFromAppName);
  if (wasUrlRecentlyLoaded(urlAsString,urlLoadStartTime) && !urlAsString.equals(mContext.getString(R.string.empty_bubble_page))) {
    Toast.makeText(mContext,R.string.duplicate_link_will_not_be_loaded,Toast.LENGTH_SHORT).show();
    return null;
  }
  URL url;
  try {
    url=new URL(urlAsString);
  }
 catch (  MalformedURLException e) {
    Toast.makeText(mContext,mContext.getString(R.string.unsupported_scheme),Toast.LENGTH_SHORT).show();
    if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
      finish();
    }
    return null;
  }
  if (Settings.get().redirectUrlToBrowser(url)) {
    Intent intent=new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(urlAsString));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    if (MainApplication.openInBrowser(mContext,intent,false)) {
      if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
        finish();
      }
      String title=String.format(mContext.getString(R.string.link_redirected),Settings.get().getDefaultBrowserLabel());
      MainApplication.saveUrlInHistory(mContext,null,urlAsString,title);
      return null;
    }
  }
  boolean showAppPicker=false;
  PackageManager packageManager=mContext.getPackageManager();
  final List<ResolveInfo> resolveInfos=Settings.get().getAppsThatHandleUrl(url.toString(),packageManager);
  ResolveInfo defaultAppResolveInfo=Settings.get().getDefaultAppForUrl(url,resolveInfos);
  if (resolveInfos != null && resolveInfos.size() > 0) {
    if (defaultAppResolveInfo != null) {
      if (handleResolveInfo(defaultAppResolveInfo,urlAsString,urlLoadStartTime)) {
        return null;
      }
    }
 else     if (resolveInfos.size() == 1) {
      if (handleResolveInfo(resolveInfos.get(0),urlAsString,urlLoadStartTime)) {
        return null;
      }
    }
 else {
      for (      ResolveInfo info : resolveInfos) {
        if (info.activityInfo.packageName.startsWith("String_Node_Str")) {
          showAppPicker=false;
          break;
        }
 else {
          showAppPicker=true;
        }
      }
    }
  }
  boolean openedFromItself=false;
  if (null != openedFromAppName && (openedFromAppName.equals(Analytics.OPENED_URL_FROM_NEW_TAB) || openedFromAppName.equals(Analytics.OPENED_URL_FROM_HISTORY))) {
    showAppPicker=true;
    openedFromItself=true;
  }
  mCanAutoDisplayLink=true;
  final TabView result=openUrlInTab(urlAsString,urlLoadStartTime,setAsCurrentTab,showAppPicker);
  if (!openedFromItself && showAppPicker && MainApplication.sShowingAppPickerDialog == false && 0 != resolveInfos.size()) {
    AlertDialog dialog=ActionItem.getActionItemPickerAlert(mContext,resolveInfos,R.string.pick_default_app,new ActionItem.OnActionItemDefaultSelectedListener(){
      @Override public void onSelected(      ActionItem actionItem,      boolean always){
        boolean loaded=false;
        for (        ResolveInfo resolveInfo : resolveInfos) {
          if (resolveInfo.activityInfo.packageName.equals(actionItem.mPackageName) && resolveInfo.activityInfo.name.equals(actionItem.mActivityClassName)) {
            if (always) {
              Settings.get().setDefaultApp(urlAsString,resolveInfo);
            }
            if (resolveInfo.activityInfo.packageName.equals(mAppPackageName)) {
              break;
            }
            loaded=MainApplication.loadIntent(mContext,actionItem.mPackageName,actionItem.mActivityClassName,urlAsString,-1,true);
            break;
          }
        }
        if (loaded) {
          Settings.get().addRedirectToApp(urlAsString);
          closeTab(result,contentViewShowing(),false);
          if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
            finish();
          }
          if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
            MainController.get().switchToBubbleView();
          }
        }
      }
    }
);
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener(){
      @Override public void onDismiss(      DialogInterface dialog){
        MainApplication.sShowingAppPickerDialog=false;
      }
    }
);
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    Util.showThemedDialog(dialog);
    MainApplication.sShowingAppPickerDialog=true;
  }
  return result;
}