nus-yam/ex-repair huggingface dataset:
Program: 109624
Project: 109624
Buggy source:
public void onClick(DialogInterface dialog,int id){
  dismiss();
  callbackInterface.onDialogDismissed();
}

Fixed version (ground truth):
@Override public void onClick(DialogInterface dialog,int which){
  ProviderAPICommand.execute(getContext(),DOWNLOAD_VPN_CERTIFICATE,provider);
}
Program: 109625
Project: 109625
Buggy source:
@Override public void setContentView(View view,ViewGroup.LayoutParams params){
  super.setContentView(view,params);
  if (provider != null)   setProviderHeaderText(provider.getName());
}

Fixed version (ground truth):
@Override public void setContentView(View view,ViewGroup.LayoutParams params){
  super.setContentView(view,params);
  if (provider != null)   setProviderHeaderText(provider.getName());
  setProgressbarColorForPreLollipop();
}
Program: 109626
Project: 109626
Buggy source:
/** 
 * Downloads a new OpenVPN certificate, attaching authenticated cookie for authenticated certificate.
 * @return true if certificate was downloaded correctly, false if provider.json is not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error.
 */
@Override protected boolean updateVpnCertificate(Provider provider){
  try {
    JSONObject providerJson=provider.getDefinition();
    String providerMainUrl=providerJson.getString(Provider.API_URL);
    URL newCertStringUrl=new URL(providerMainUrl + "String_Node_Str" + providerJson.getString(Provider.API_VERSION)+ "String_Node_Str"+ PROVIDER_VPN_CERTIFICATE);
    String certString=downloadWithProviderCA(provider.getCaCert(),newCertStringUrl.toString());
    if (ConfigHelper.checkErroneousDownload(certString))     return false;
 else     return loadCertificate(certString);
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
catch (  JSONException e) {
    e.printStackTrace();
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Downloads a new OpenVPN certificate, attaching authenticated cookie for authenticated certificate.
 * @return true if certificate was downloaded correctly, false if provider.json is not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error.
 */
@Override protected boolean updateVpnCertificate(Provider provider){
  try {
    JSONObject providerJson=provider.getDefinition();
    String providerMainUrl=providerJson.getString(Provider.API_URL);
    URL newCertStringUrl=new URL(providerMainUrl + "String_Node_Str" + providerJson.getString(Provider.API_VERSION)+ "String_Node_Str"+ PROVIDER_VPN_CERTIFICATE);
    String certString=downloadWithProviderCA(provider.getCaCert(),newCertStringUrl.toString());
    if (ConfigHelper.checkErroneousDownload(certString))     return false;
 else     return loadCertificate(provider,certString);
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
catch (  JSONException e) {
    e.printStackTrace();
    return false;
  }
}
Program: 109627
Project: 109627
Buggy source:
/** 
 * Retrys setup of last used provider, allows bypassing ca certificate validation.
 */
@Override public void retrySetUpProvider(){
  cancelSettingUpProvider();
  if (!ProviderAPI.caCertDownloaded()) {
    addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl(),ProviderAPI.lastDangerOn());
  }
 else {
    showProgressBar();
    adapter.hideAllBut(adapter.indexOf(selectedProvider));
    Intent provider_API_command=new Intent(this,ProviderAPI.class);
    provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
    provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY,providerAPIResultReceiver);
    Bundle parameters=new Bundle();
    parameters.putString(Provider.MAIN_URL,selectedProvider.getMainUrl().toString());
    provider_API_command.putExtra(ProviderAPI.PARAMETERS,parameters);
    startService(provider_API_command);
  }
}

Fixed version (ground truth):
/** 
 * Retrys setup of last used provider, allows bypassing ca certificate validation.
 */
@Override public void retrySetUpProvider(){
  cancelSettingUpProvider();
  if (!ProviderAPI.caCertDownloaded()) {
    addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl(),ProviderAPI.lastDangerOn());
  }
 else {
    showProgressBar();
    adapter.hideAllBut(adapter.indexOf(selectedProvider));
    Intent providerAPICommand=new Intent(this,ProviderAPI.class);
    providerAPICommand.setAction(ProviderAPI.SET_UP_PROVIDER);
    Bundle parameters=new Bundle();
    parameters.putString(Provider.MAIN_URL,selectedProvider.getMainUrl().toString());
    providerAPICommand.putExtra(ProviderAPI.PARAMETERS,parameters);
    startService(providerAPICommand);
  }
}
Program: 109628
Project: 109628
Buggy source:
/** 
 * Asks ProviderAPI to download a new provider.json file
 * @param danger_on tells if HTTPS client should bypass certificate errors
 */
public void setUpProvider(boolean danger_on){
  mConfigState.setAction(SETTING_UP_PROVIDER);
  Intent provider_API_command=new Intent(this,ProviderAPI.class);
  Bundle parameters=new Bundle();
  parameters.putString(Provider.MAIN_URL,selectedProvider.getMainUrl().toString());
  parameters.putBoolean(ProviderItem.DANGER_ON,danger_on);
  if (selectedProvider.hasCertificatePin()) {
    parameters.putString(Provider.CA_CERT_FINGERPRINT,selectedProvider.certificatePin());
  }
  if (selectedProvider.hasCaCert()) {
    parameters.putString(Provider.CA_CERT,selectedProvider.getCaCert());
  }
  if (selectedProvider.hasDefinition()) {
    parameters.putString(Provider.KEY,selectedProvider.getDefinition().toString());
  }
  provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
  provider_API_command.putExtra(ProviderAPI.PARAMETERS,parameters);
  provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY,providerAPIResultReceiver);
  startService(provider_API_command);
}

Fixed version (ground truth):
/** 
 * Asks ProviderAPI to download a new provider.json file
 * @param danger_on tells if HTTPS client should bypass certificate errors
 */
public void setUpProvider(boolean danger_on){
  mConfigState.setAction(SETTING_UP_PROVIDER);
  Intent provider_API_command=new Intent(this,ProviderAPI.class);
  Bundle parameters=new Bundle();
  parameters.putString(Provider.MAIN_URL,selectedProvider.getMainUrl().toString());
  parameters.putBoolean(ProviderItem.DANGER_ON,danger_on);
  if (selectedProvider.hasCertificatePin()) {
    parameters.putString(Provider.CA_CERT_FINGERPRINT,selectedProvider.certificatePin());
  }
  if (selectedProvider.hasCaCert()) {
    parameters.putString(Provider.CA_CERT,selectedProvider.getCaCert());
  }
  if (selectedProvider.hasDefinition()) {
    parameters.putString(Provider.KEY,selectedProvider.getDefinition().toString());
  }
  provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
  provider_API_command.putExtra(ProviderAPI.PARAMETERS,parameters);
  startService(provider_API_command);
}
Program: 109629
Project: 109629
Buggy source:
private void switchProvider(){
  if (provider.hasEIP())   eip_fragment.stopEipIfPossible();
  Map<String,?> allEntries=preferences.getAll();
  List<String> lastProvidersKeys=new ArrayList<>();
  for (  Map.Entry<String,?> entry : allEntries.entrySet()) {
    if (entry.getKey().startsWith(Provider.KEY + "String_Node_Str") || entry.getKey().startsWith(Provider.CA_CERT + "String_Node_Str") || entry.getKey().startsWith(Provider.CA_CERT_FINGERPRINT + "String_Node_Str")) {
      continue;
    }
    lastProvidersKeys.add(entry.getKey());
  }
  SharedPreferences.Editor preferenceEditor=preferences.edit();
  for (  String key : lastProvidersKeys) {
    preferenceEditor.remove(key);
  }
  preferenceEditor.apply();
  switching_provider=false;
  startActivityForResult(new Intent(this,ConfigurationWizard.class),SWITCH_PROVIDER);
}

Fixed version (ground truth):
private void switchProvider(){
  if (provider.hasEIP())   eip_fragment.stopEipIfPossible();
  clearDataOfLastProvider();
  switching_provider=false;
  startActivityForResult(new Intent(this,ConfigurationWizard.class),SWITCH_PROVIDER);
}
Program: 109630
Project: 109630
Buggy source:
@Override protected void onCreate(@Nullable Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  preferences=getSharedPreferences(Constants.SHARED_PREFERENCES,MODE_PRIVATE);
  Log.d(TAG,"String_Node_Str");
switch (checkAppStart()) {
case NORMAL:
    break;
case FIRST:
  break;
case UPGRADE:
executeUpgrade();
break;
case DOWNGRADE:
break;
}
ProviderAPICommand.initialize(getApplicationContext());
VpnStatus.initLogCache(getApplicationContext().getCacheDir());
User.init(getString(R.string.default_username));
Intent intent=new Intent(this,Dashboard.class);
startActivity(intent);
}

Fixed version (ground truth):
@Override protected void onCreate(@Nullable Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  preferences=getSharedPreferences(Constants.SHARED_PREFERENCES,MODE_PRIVATE);
  Log.d(TAG,"String_Node_Str");
switch (checkAppStart()) {
case NORMAL:
    break;
case FIRST:
  storeAppVersion();
break;
case UPGRADE:
executeUpgrade();
break;
case DOWNGRADE:
break;
}
ProviderAPICommand.initialize(getApplicationContext());
VpnStatus.initLogCache(getApplicationContext().getCacheDir());
User.init(getString(R.string.default_username));
Intent intent=new Intent(this,Dashboard.class);
startActivity(intent);
}
Program: 109631
Project: 109631
Buggy source:
/** 
 * execute necessary upgrades for version change
 */
private void executeUpgrade(){
  if (hasNewFeature(FeatureVersionCode.MULTIPLE_PROFILES)) {
  }
  preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION,versionCode).apply();
}

Fixed version (ground truth):
/** 
 * execute necessary upgrades for version change
 */
private void executeUpgrade(){
  if (hasNewFeature(FeatureVersionCode.MULTIPLE_PROFILES)) {
  }
  storeAppVersion();
}
Program: 109632
Project: 109632
Buggy source:
public TestEIP(Class<EIP> activityClass){
  super(activityClass);
  context=getSystemContext();
  intent=new Intent(context,EIP.class);
  preferences=context.getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE);
}

Fixed version (ground truth):
public TestEIP(Class<EIP> activityClass){
  super(activityClass);
  context=getSystemContext();
  intent=new Intent(context,EIP.class);
  preferences=context.getSharedPreferences(Constants.SHARED_PREFERENCES,Context.MODE_PRIVATE);
}
Program: 109633
Project: 109633
Buggy source:
@Override protected void onCreate(@Nullable Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  preferences=getSharedPreferences(Constants.SHARED_PREFERENCES,MODE_PRIVATE);
  Log.d(TAG,"String_Node_Str");
switch (checkAppStart()) {
case NORMAL:
    break;
case FIRST:
  break;
case UPGRADE:
executeUpgrade();
break;
case DOWNGRADE:
break;
}
ProviderAPICommand.initialize(this);
VpnStatus.initLogCache(getApplicationContext().getCacheDir());
User.init(getString(R.string.default_username));
Intent intent=new Intent(this,Dashboard.class);
startActivity(intent);
}

Fixed version (ground truth):
@Override protected void onCreate(@Nullable Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  preferences=getSharedPreferences(Constants.SHARED_PREFERENCES,MODE_PRIVATE);
  Log.d(TAG,"String_Node_Str");
switch (checkAppStart()) {
case NORMAL:
    break;
case FIRST:
  break;
case UPGRADE:
executeUpgrade();
break;
case DOWNGRADE:
break;
}
ProviderAPICommand.initialize(getApplicationContext());
VpnStatus.initLogCache(getApplicationContext().getCacheDir());
User.init(getString(R.string.default_username));
Intent intent=new Intent(this,Dashboard.class);
startActivity(intent);
}
Program: 109634
Project: 109634
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  preferences=context.getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE);
  boolean providerConfigured=!preferences.getString(VPN_CERTIFICATE,"String_Node_Str").isEmpty();
  boolean startOnBoot=preferences.getBoolean(RESTART_ON_BOOT,false);
  boolean isAlwaysOnConfigured=preferences.getBoolean(IS_ALWAYS_ON,false);
  Log.d("String_Node_Str","String_Node_Str" + providerConfigured + "String_Node_Str"+ startOnBoot+ "String_Node_Str"+ isAlwaysOnConfigured);
  if (providerConfigured) {
    if (isAlwaysOnConfigured) {
      return;
    }
    if (startOnBoot) {
      Intent dashboard_intent=new Intent(context,Dashboard.class);
      dashboard_intent.putExtra(RESTART_ON_BOOT,true);
      dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(dashboard_intent);
    }
  }
 else {
    if (isAlwaysOnConfigured) {
      Intent dashboard_intent=new Intent(context,Dashboard.class);
      dashboard_intent.putExtra(Dashboard.ACTION_CONFIGURE_ALWAYS_ON_PROFILE,true);
      dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(dashboard_intent);
    }
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  if (intent == null || !ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
    return;
  }
  preferences=context.getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE);
  boolean providerConfigured=!preferences.getString(VPN_CERTIFICATE,"String_Node_Str").isEmpty();
  boolean startOnBoot=preferences.getBoolean(RESTART_ON_BOOT,false);
  boolean isAlwaysOnConfigured=preferences.getBoolean(IS_ALWAYS_ON,false);
  Log.d("String_Node_Str","String_Node_Str" + providerConfigured + "String_Node_Str"+ startOnBoot+ "String_Node_Str"+ isAlwaysOnConfigured);
  if (providerConfigured) {
    if (isAlwaysOnConfigured) {
      return;
    }
    if (startOnBoot) {
      Intent dashboard_intent=new Intent(context,Dashboard.class);
      dashboard_intent.putExtra(RESTART_ON_BOOT,true);
      dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(dashboard_intent);
    }
  }
 else {
    if (isAlwaysOnConfigured) {
      Intent dashboard_intent=new Intent(context,Dashboard.class);
      dashboard_intent.putExtra(Dashboard.ACTION_CONFIGURE_ALWAYS_ON_PROFILE,true);
      dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(dashboard_intent);
    }
  }
}
Program: 109635
Project: 109635
Buggy source:
private void onItemSelectedUi(){
  startProgressBar();
  adapter.hideAllBut(adapter.indexOf(selected_provider));
}

Fixed version (ground truth):
private void onItemSelectedUi(){
  adapter.hideAllBut(adapter.indexOf(selected_provider));
  startProgressBar();
}
Program: 109636
Project: 109636
Buggy source:
private void restoreState(Bundle savedInstanceState){
  progressbar_text=savedInstanceState.getString(PROGRESSBAR_TEXT,"String_Node_Str");
  provider_name=savedInstanceState.getString(Provider.NAME,"String_Node_Str");
  selected_provider=savedInstanceState.getParcelable(Provider.KEY);
  progress=savedInstanceState.getInt(PROGRESSBAR_NUMBER,-1);
  if (fragment_manager.findFragmentByTag(ProviderDetailFragment.TAG) == null && setting_up_provider) {
    onItemSelectedUi();
    if (progress > 0)     mProgressBar.setProgress(progress);
  }
}

Fixed version (ground truth):
private void restoreState(Bundle savedInstanceState){
  progressbar_text=savedInstanceState.getString(PROGRESSBAR_TEXT,"String_Node_Str");
  selected_provider=savedInstanceState.getParcelable(Provider.KEY);
  if (fragment_manager.findFragmentByTag(ProviderDetailFragment.TAG) == null && SETTING_UP_PROVIDER.equals(mConfigState.getAction())) {
    onItemSelectedUi();
  }
}
Program: 109637
Project: 109637
Buggy source:
/** 
 * Asks ProviderAPI to download a new provider.json file
 * @param danger_on         tells if HTTPS client should bypass certificate errors
 */
public void setUpProvider(boolean danger_on){
  Intent provider_API_command=new Intent(this,ProviderAPI.class);
  Bundle parameters=new Bundle();
  parameters.putString(Provider.MAIN_URL,selected_provider.mainUrl().getUrl().toString());
  parameters.putBoolean(ProviderItem.DANGER_ON,danger_on);
  parameters.putString(Provider.CA_CERT_FINGERPRINT,selected_provider.certificatePin());
  provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
  provider_API_command.putExtra(ProviderAPI.PARAMETERS,parameters);
  provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY,providerAPI_result_receiver);
  startService(provider_API_command);
  setting_up_provider=true;
}

Fixed version (ground truth):
/** 
 * Asks ProviderAPI to download a new provider.json file
 * @param danger_on         tells if HTTPS client should bypass certificate errors
 */
public void setUpProvider(boolean danger_on){
  mConfigState.setAction(SETTING_UP_PROVIDER);
  Intent provider_API_command=new Intent(this,ProviderAPI.class);
  Bundle parameters=new Bundle();
  parameters.putString(Provider.MAIN_URL,selected_provider.mainUrl().getUrl().toString());
  parameters.putBoolean(ProviderItem.DANGER_ON,danger_on);
  parameters.putString(Provider.CA_CERT_FINGERPRINT,selected_provider.certificatePin());
  provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
  provider_API_command.putExtra(ProviderAPI.PARAMETERS,parameters);
  provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY,providerAPI_result_receiver);
  startService(provider_API_command);
}
Program: 109638
Project: 109638
Buggy source:
private void stopSettingUpProvider(){
  ProviderAPI.stop();
  mProgressBar.setVisibility(ProgressBar.GONE);
  mProgressBar.setProgress(0);
  progressbar_description.setVisibility(TextView.GONE);
  cancelSettingUpProvider();
}

Fixed version (ground truth):
private void stopSettingUpProvider(){
  ProviderAPI.stop();
  mProgressBar.setVisibility(GONE);
  mProgressBar.setProgress(0);
  progressbar_description.setVisibility(GONE);
  cancelSettingUpProvider();
}
Program: 109639
Project: 109639
Buggy source:
private void startProgressBar(){
  mProgressBar.setVisibility(ProgressBar.VISIBLE);
  progressbar_description.setVisibility(TextView.VISIBLE);
  mProgressBar.setProgress(0);
  mProgressBar.setMax(3);
  int measured_height=listItemHeight();
  mProgressBar.setTranslationY(measured_height);
  progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight());
}

Fixed version (ground truth):
private void startProgressBar(){
  showProgressBar();
  mProgressBar.setProgress(0);
  mProgressBar.setMax(3);
  int measured_height=listItemHeight();
  mProgressBar.setTranslationY(measured_height);
  progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight());
}
Program: 109640
Project: 109640
Buggy source:
/** 
 * Once selected a provider, this fragment offers the user to log in, use it anonymously (if possible) or cancel his/her election pressing the back button.
 */
private void showProviderDetails(){
  if (setting_up_provider) {
    FragmentTransaction fragment_transaction=fragment_manager.removePreviousFragment(ProviderDetailFragment.TAG);
    DialogFragment newFragment=ProviderDetailFragment.newInstance();
    newFragment.show(fragment_transaction,ProviderDetailFragment.TAG);
    setting_up_provider=false;
  }
}

Fixed version (ground truth):
/** 
 * Once selected a provider, this fragment offers the user to log in, use it anonymously (if possible) or cancel his/her election pressing the back button.
 */
private void showProviderDetails(){
  mConfigState.setAction(SETTING_UP_PROVIDER_SHOW_PROVIDER_DETILS);
  try {
    FragmentTransaction fragment_transaction=fragment_manager.removePreviousFragment(ProviderDetailFragment.TAG);
    DialogFragment newFragment=ProviderDetailFragment.newInstance();
    newFragment.show(fragment_transaction,ProviderDetailFragment.TAG);
  }
 catch (  IllegalStateException e) {
    e.printStackTrace();
  }
}
Program: 109641
Project: 109641
Buggy source:
@Override public void onReceiveResult(int resultCode,Bundle resultData){
  if (resultCode == ProviderAPI.PROVIDER_OK) {
    mConfigState.setAction(PROVIDER_SET);
    try {
      String provider_json_string=preferences.getString(Provider.KEY,"String_Node_Str");
      if (!provider_json_string.isEmpty())       selected_provider.define(new JSONObject(provider_json_string));
    }
 catch (    JSONException e) {
      e.printStackTrace();
    }
    if (preferences.getBoolean(Constants.ALLOWED_ANON,false)) {
      mConfigState.putExtra(SERVICES_RETRIEVED,true);
      downloadVpnCertificate();
    }
 else {
      mProgressBar.incrementProgressBy(1);
      hideProgressBar();
      showProviderDetails();
    }
  }
 else   if (resultCode == ProviderAPI.PROVIDER_NOK) {
    hideProgressBar();
    preferences.edit().remove(Provider.KEY).apply();
    setting_up_provider=false;
    String reason_to_fail=resultData.getString(ProviderAPI.ERRORS);
    showDownloadFailedDialog(reason_to_fail);
  }
 else   if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
    mProgressBar.incrementProgressBy(1);
    hideProgressBar();
    showProviderDetails();
  }
 else   if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
    hideProgressBar();
    cancelSettingUpProvider();
    Toast.makeText(getApplicationContext(),R.string.provider_problem,Toast.LENGTH_LONG).show();
  }
 else   if (resultCode == AboutActivity.VIEWED) {
  }
}

Fixed version (ground truth):
@Override public void onReceiveResult(int resultCode,Bundle resultData){
  if (resultCode == ProviderAPI.PROVIDER_OK) {
    try {
      String provider_json_string=preferences.getString(Provider.KEY,"String_Node_Str");
      if (!provider_json_string.isEmpty())       selected_provider.define(new JSONObject(provider_json_string));
    }
 catch (    JSONException e) {
      e.printStackTrace();
    }
    if (preferences.getBoolean(Constants.ALLOWED_ANON,false)) {
      mConfigState.putExtra(SERVICES_RETRIEVED,true);
      downloadVpnCertificate();
    }
 else {
      mProgressBar.incrementProgressBy(1);
      hideProgressBar();
      showProviderDetails();
    }
  }
 else   if (resultCode == ProviderAPI.PROVIDER_NOK) {
    mConfigState.setAction(PROVIDER_NOT_SET);
    hideProgressBar();
    preferences.edit().remove(Provider.KEY).apply();
    String reason_to_fail=resultData.getString(ProviderAPI.ERRORS);
    showDownloadFailedDialog(reason_to_fail);
  }
 else   if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
    mProgressBar.incrementProgressBy(1);
    hideProgressBar();
    showProviderDetails();
  }
 else   if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
    mConfigState.setAction(PROVIDER_NOT_SET);
    hideProgressBar();
    setResult(RESULT_CANCELED,mConfigState);
    Toast.makeText(getApplicationContext(),R.string.provider_problem,Toast.LENGTH_LONG).show();
  }
 else   if (resultCode == AboutActivity.VIEWED) {
  }
}
Program: 109642
Project: 109642
Buggy source:
@Override public void login(){
  Intent ask_login=new Intent();
  ask_login.putExtra(SessionDialog.TAG,SessionDialog.TAG);
  ask_login.putExtra(Provider.KEY,selected_provider);
  setResult(RESULT_OK,ask_login);
  setting_up_provider=false;
  finish();
}

Fixed version (ground truth):
@Override public void login(){
  mConfigState.setAction(PROVIDER_SET);
  Intent ask_login=new Intent();
  ask_login.putExtra(SessionDialog.TAG,SessionDialog.TAG);
  ask_login.putExtra(Provider.KEY,selected_provider);
  setResult(RESULT_OK,ask_login);
  finish();
}
Program: 109643
Project: 109643
Buggy source:
@Override public void use_anonymously(){
  Intent pass_provider=new Intent();
  pass_provider.putExtra(Provider.KEY,selected_provider);
  setResult(RESULT_OK,pass_provider);
  setting_up_provider=false;
  finish();
}

Fixed version (ground truth):
@Override public void use_anonymously(){
  mConfigState.setAction(PROVIDER_SET);
  Intent pass_provider=new Intent();
  pass_provider.putExtra(Provider.KEY,selected_provider);
  setResult(RESULT_OK,pass_provider);
  finish();
}
Program: 109644
Project: 109644
Buggy source:
@Override public void onBackPressed(){
  if (setting_up_provider) {
    stopSettingUpProvider();
  }
 else {
    askDashboardToQuitApp();
    super.onBackPressed();
  }
}

Fixed version (ground truth):
@Override public void onBackPressed(){
  if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) {
    stopSettingUpProvider();
  }
 else {
    askDashboardToQuitApp();
    super.onBackPressed();
  }
}
Program: 109645
Project: 109645
Buggy source:
public void cancelSettingUpProvider(){
  adapter.showAllProviders();
  setting_up_provider=false;
  preferences.edit().remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit();
}

Fixed version (ground truth):
public void cancelSettingUpProvider(){
  mConfigState.setAction(PROVIDER_NOT_SET);
  adapter.showAllProviders();
  preferences.edit().remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit();
}
Program: 109646
Project: 109646
Buggy source:
@OnItemClick(R.id.provider_list) void onItemSelected(int position){
  selected_provider=adapter.getItem(position);
  onItemSelectedLogic();
  onItemSelectedUi();
}

Fixed version (ground truth):
@OnItemClick(R.id.provider_list) void onItemSelected(int position){
  if (SETTING_UP_PROVIDER.equals(mConfigState.getAction()) || SETTING_UP_PROVIDER_SHOW_PROVIDER_DETILS.equals(mConfigState.getAction())) {
    return;
  }
  mConfigState.setAction(SETTING_UP_PROVIDER);
  selected_provider=adapter.getItem(position);
  onItemSelectedLogic();
  onItemSelectedUi();
}
Program: 109647
Project: 109647
Buggy source:
private int listItemHeight(){
  View listItem=adapter.getView(0,null,provider_list_view);
  listItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT));
  WindowManager wm=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
  Display display=wm.getDefaultDisplay();
  int screenWidth=display.getWidth();
  int listViewWidth=screenWidth - 10 - 10;
  int widthSpec=View.MeasureSpec.makeMeasureSpec(listViewWidth,View.MeasureSpec.AT_MOST);
  listItem.measure(widthSpec,0);
  return listItem.getMeasuredHeight();
}

Fixed version (ground truth):
private int listItemHeight(){
  View listItem=adapter.getView(0,null,provider_list_view);
  listItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT));
  WindowManager wm=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
  Display display=wm.getDefaultDisplay();
  int screenWidth=display.getWidth();
  int listViewWidth=screenWidth - 10 - 10;
  int widthSpec=MeasureSpec.makeMeasureSpec(listViewWidth,MeasureSpec.AT_MOST);
  listItem.measure(widthSpec,0);
  return listItem.getMeasuredHeight();
}
Program: 109648
Project: 109648
Buggy source:
private void hideProgressBar(){
  mProgressBar.setVisibility(ProgressBar.INVISIBLE);
  progressbar_description.setVisibility(TextView.INVISIBLE);
}

Fixed version (ground truth):
private void hideProgressBar(){
  mProgressBar.setVisibility(INVISIBLE);
  progressbar_description.setVisibility(INVISIBLE);
}
Program: 109649
Project: 109649
Buggy source:
@Override public void onCancel(DialogInterface dialog){
  super.onCancel(dialog);
  SharedPreferences.Editor editor=getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES,Activity.MODE_PRIVATE).edit();
  editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit();
  interface_with_configuration_wizard.showAllProviders();
}

Fixed version (ground truth):
@Override public void onCancel(DialogInterface dialog){
  super.onCancel(dialog);
  SharedPreferences.Editor editor=getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES,Activity.MODE_PRIVATE).edit();
  editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit();
  interface_with_configuration_wizard.cancelAndShowAllProviders();
}
Program: 109650
Project: 109650
Buggy source:
protected static RSAPrivateKey parseRsaKeyFromString(String RsaKeyString){
  RSAPrivateKey key=null;
  try {
    KeyFactory kf=KeyFactory.getInstance("String_Node_Str","String_Node_Str");
    RsaKeyString=RsaKeyString.replaceFirst("String_Node_Str","String_Node_Str").replaceFirst("String_Node_Str","String_Node_Str");
    PKCS8EncodedKeySpec keySpec=new PKCS8EncodedKeySpec(Base64.decode(RsaKeyString,Base64.DEFAULT));
    key=(RSAPrivateKey)kf.generatePrivate(keySpec);
  }
 catch (  InvalidKeySpecException e) {
    e.printStackTrace();
    return null;
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
    return null;
  }
catch (  NoSuchProviderException e) {
    e.printStackTrace();
    return null;
  }
  return key;
}

Fixed version (ground truth):
protected static RSAPrivateKey parseRsaKeyFromString(String rsaKeyString){
  RSAPrivateKey key=null;
  try {
    KeyFactory kf=KeyFactory.getInstance("String_Node_Str","String_Node_Str");
    rsaKeyString=rsaKeyString.replaceFirst("String_Node_Str","String_Node_Str").replaceFirst("String_Node_Str","String_Node_Str");
    PKCS8EncodedKeySpec keySpec=new PKCS8EncodedKeySpec(Base64.decode(rsaKeyString,Base64.DEFAULT));
    key=(RSAPrivateKey)kf.generatePrivate(keySpec);
  }
 catch (  InvalidKeySpecException e) {
    e.printStackTrace();
    return null;
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
    return null;
  }
catch (  NoSuchProviderException e) {
    e.printStackTrace();
    return null;
  }
catch (  NullPointerException e) {
    e.printStackTrace();
    return null;
  }
  return key;
}
Program: 109651
Project: 109651
Buggy source:
protected boolean loadCertificate(String cert_string){
  try {
    String certificateString=null, keyString=null;
    String[] certAndKey=cert_string.split("String_Node_Str");
    for (int i=0; i < certAndKey.length - 1; i++) {
      if (certAndKey[i].contains("String_Node_Str")) {
        keyString=certAndKey[i++] + certAndKey[i];
      }
 else       if (certAndKey[i].contains("String_Node_Str")) {
        certificateString=certAndKey[i++] + certAndKey[i];
      }
    }
    RSAPrivateKey key=ConfigHelper.parseRsaKeyFromString(keyString);
    keyString=Base64.encodeToString(key.getEncoded(),Base64.DEFAULT);
    preferences.edit().putString(Constants.PRIVATE_KEY,"String_Node_Str" + keyString + "String_Node_Str").commit();
    X509Certificate certificate=ConfigHelper.parseX509CertificateFromString(certificateString);
    certificateString=Base64.encodeToString(certificate.getEncoded(),Base64.DEFAULT);
    preferences.edit().putString(Constants.VPN_CERTIFICATE,"String_Node_Str" + certificateString + "String_Node_Str").commit();
    return true;
  }
 catch (  CertificateException e) {
    e.printStackTrace();
    return false;
  }
}

Fixed version (ground truth):
protected boolean loadCertificate(String cert_string){
  if (cert_string == null) {
    return false;
  }
  try {
    String certificateString=null, keyString=null;
    String[] certAndKey=cert_string.split("String_Node_Str");
    for (int i=0; i < certAndKey.length - 1; i++) {
      if (certAndKey[i].contains("String_Node_Str")) {
        keyString=certAndKey[i++] + certAndKey[i];
      }
 else       if (certAndKey[i].contains("String_Node_Str")) {
        certificateString=certAndKey[i++] + certAndKey[i];
      }
    }
    RSAPrivateKey key=ConfigHelper.parseRsaKeyFromString(keyString);
    keyString=Base64.encodeToString(key.getEncoded(),Base64.DEFAULT);
    preferences.edit().putString(Constants.PRIVATE_KEY,"String_Node_Str" + keyString + "String_Node_Str").commit();
    X509Certificate certificate=ConfigHelper.parseX509CertificateFromString(certificateString);
    certificateString=Base64.encodeToString(certificate.getEncoded(),Base64.DEFAULT);
    preferences.edit().putString(Constants.VPN_CERTIFICATE,"String_Node_Str" + certificateString + "String_Node_Str").commit();
    return true;
  }
 catch (  CertificateException e) {
    e.printStackTrace();
    return false;
  }
}
Program: 109652
Project: 109652
Buggy source:
private void addProvider(String url){
  boolean is_new_provider=!solo.searchText(url);
  if (is_new_provider)   added_providers=added_providers + 1;
  solo.clickOnActionBarItem(R.id.new_provider);
  solo.enterText(0,url);
  if (BuildConfig.FLAVOR.equals("String_Node_Str")) {
    solo.clickOnCheckBox(0);
  }
  solo.clickOnText(solo.getString(R.string.save));
  waitForProviderDetails();
  solo.goBack();
}

Fixed version (ground truth):
private void addProvider(String url,boolean expectSuccess){
  solo.clickOnActionBarItem(R.id.new_provider);
  solo.enterText(0,url);
  if (BuildConfig.FLAVOR.equals("String_Node_Str")) {
    solo.clickOnCheckBox(0);
  }
  solo.clickOnText(solo.getString(R.string.save));
  if (expectSuccess) {
    waitForProviderDetails();
  }
 else {
    waitForNoValidProviderError();
  }
  solo.goBack();
}
Program: 109653
Project: 109653
Buggy source:
public void testAddNewProvider(){
  addProvider("String_Node_Str");
}

Fixed version (ground truth):
public void testAddNewProvider(){
  addProvider("String_Node_Str",true);
}
Program: 109654
Project: 109654
Buggy source:
private int shownProviders(){
  return solo.getCurrentViews(ListView.class).get(0).getCount();
}

Fixed version (ground truth):
/** 
 * Tests should run independently from each other. We need a better approach to test the amount of providers added
 */
private int shownProviders(){
  return solo.getCurrentViews(ListView.class).get(0).getCount();
}
Program: 109655
Project: 109655
Buggy source:
private Bundle getAndSetProviderJson(String provider_main_url,boolean danger_on,String provider_ca_cert_fingerprint){
  Bundle result=new Bundle();
  if (go_ahead) {
    String provider_dot_json_string;
    if (provider_ca_cert_fingerprint.isEmpty())     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str",danger_on);
 else     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str",danger_on,provider_ca_cert_fingerprint);
    try {
      JSONObject provider_json=new JSONObject(provider_dot_json_string);
      provider_api_url=provider_json.getString(Provider.API_URL) + "String_Node_Str" + provider_json.getString(Provider.API_VERSION);
      String name=provider_json.getString(Provider.NAME);
      preferences.edit().putString(Provider.KEY,provider_json.toString()).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_ANON,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit();
      result.putBoolean(RESULT_KEY,true);
    }
 catch (    JSONException e) {
      String reason_to_fail=pickErrorMessage(provider_dot_json_string);
      result.putString(ERRORS,reason_to_fail);
      result.putBoolean(RESULT_KEY,false);
    }
  }
  return result;
}

Fixed version (ground truth):
private Bundle getAndSetProviderJson(String provider_main_url,boolean danger_on,String provider_ca_cert_fingerprint){
  Bundle result=new Bundle();
  if (go_ahead) {
    String provider_dot_json_string;
    if (provider_ca_cert_fingerprint.isEmpty())     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str",danger_on);
 else     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str",danger_on,provider_ca_cert_fingerprint);
    if (!isValidJson(provider_dot_json_string)) {
      result.putString(ERRORS,getString(malformed_url));
      result.putBoolean(RESULT_KEY,false);
      return result;
    }
    try {
      JSONObject provider_json=new JSONObject(provider_dot_json_string);
      provider_api_url=provider_json.getString(Provider.API_URL) + "String_Node_Str" + provider_json.getString(Provider.API_VERSION);
      String name=provider_json.getString(Provider.NAME);
      preferences.edit().putString(Provider.KEY,provider_json.toString()).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_ANON,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit();
      result.putBoolean(RESULT_KEY,true);
    }
 catch (    JSONException e) {
      String reason_to_fail=pickErrorMessage(provider_dot_json_string);
      result.putString(ERRORS,reason_to_fail);
      result.putBoolean(RESULT_KEY,false);
    }
  }
  return result;
}
Program: 109656
Project: 109656
Buggy source:
/** 
 * Tries to download the contents of the provided url using commercially validated CA certificate from chosen provider. <p/> If danger_on flag is true, SSL exceptions will be managed by futher methods that will try to use some bypass methods.
 * @param string_url
 * @param danger_on  if the user completely trusts this provider
 * @return
 */
private String downloadWithCommercialCA(String string_url,boolean danger_on){
  String responseString;
  JSONObject errorJson=new JSONObject();
  OkHttpClient okHttpClient=initCommercialCAHttpClient(errorJson);
  if (okHttpClient == null) {
    return errorJson.toString();
  }
  List<Pair<String,String>> headerArgs=getAuthorizationHeader();
  responseString=sendGetStringToServer(string_url,headerArgs,okHttpClient);
  if (responseString.contains(ERRORS)) {
    try {
      JSONObject responseErrorJson=new JSONObject(responseString);
      if (danger_on && responseErrorJson.getString(ERRORS).equals(getString(R.string.certificate_error))) {
        responseString=downloadWithProviderCA(string_url,danger_on);
      }
    }
 catch (    JSONException e) {
      e.printStackTrace();
    }
  }
  return responseString;
}

Fixed version (ground truth):
/** 
 * Tries to download the contents of the provided url using commercially validated CA certificate from chosen provider. <p/> If danger_on flag is true, SSL exceptions will be managed by futher methods that will try to use some bypass methods.
 * @param string_url
 * @param danger_on  if the user completely trusts this provider
 * @return
 */
private String downloadWithCommercialCA(String string_url,boolean danger_on){
  String responseString;
  JSONObject errorJson=new JSONObject();
  OkHttpClient okHttpClient=initCommercialCAHttpClient(errorJson);
  if (okHttpClient == null) {
    return errorJson.toString();
  }
  List<Pair<String,String>> headerArgs=getAuthorizationHeader();
  responseString=sendGetStringToServer(string_url,headerArgs,okHttpClient);
  if (responseString != null && responseString.contains(ERRORS)) {
    try {
      JSONObject responseErrorJson=new JSONObject(responseString);
      if (danger_on && responseErrorJson.getString(ERRORS).equals(getString(R.string.certificate_error))) {
        responseString=downloadWithProviderCA(string_url,danger_on);
      }
    }
 catch (    JSONException e) {
      e.printStackTrace();
    }
  }
  return responseString;
}
Program: 109657
Project: 109657
Buggy source:
/** 
 * Downloads a new OpenVPN certificate, attaching authenticated cookie for authenticated certificate.
 * @return true if certificate was downloaded correctly, false if provider.json is not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error.
 */
@Override protected boolean updateVpnCertificate(){
  try {
    JSONObject provider_json=new JSONObject(preferences.getString(Provider.KEY,"String_Node_Str"));
    String provider_main_url=provider_json.getString(Provider.API_URL);
    URL new_cert_string_url=new URL(provider_main_url + "String_Node_Str" + provider_json.getString(Provider.API_VERSION)+ "String_Node_Str"+ Constants.VPN_CERTIFICATE);
    String cert_string=downloadWithProviderCA(new_cert_string_url.toString(),last_danger_on);
    if (cert_string.isEmpty() || ConfigHelper.checkErroneousDownload(cert_string))     return false;
 else     return loadCertificate(cert_string);
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
catch (  JSONException e) {
    e.printStackTrace();
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Downloads a new OpenVPN certificate, attaching authenticated cookie for authenticated certificate.
 * @return true if certificate was downloaded correctly, false if provider.json is not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error.
 */
@Override protected boolean updateVpnCertificate(){
  try {
    JSONObject provider_json=new JSONObject(preferences.getString(Provider.KEY,"String_Node_Str"));
    String provider_main_url=provider_json.getString(Provider.API_URL);
    URL new_cert_string_url=new URL(provider_main_url + "String_Node_Str" + provider_json.getString(Provider.API_VERSION)+ "String_Node_Str"+ Constants.VPN_CERTIFICATE);
    String cert_string=downloadWithProviderCA(new_cert_string_url.toString(),last_danger_on);
    if (cert_string == null || cert_string.isEmpty() || ConfigHelper.checkErroneousDownload(cert_string))     return false;
 else     return loadCertificate(cert_string);
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
catch (  JSONException e) {
    e.printStackTrace();
    return false;
  }
}
Program: 109658
Project: 109658
Buggy source:
/** 
 * Downloads the eip-service.json from a given URL, and saves eip service capabilities including the offered gateways
 * @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the download was successful.
 */
@Override protected Bundle getAndSetEipServiceJson(){
  Bundle result=new Bundle();
  String eip_service_json_string="String_Node_Str";
  if (go_ahead) {
    try {
      JSONObject provider_json=new JSONObject(preferences.getString(Provider.KEY,"String_Node_Str"));
      String eip_service_url=provider_json.getString(Provider.API_URL) + "String_Node_Str" + provider_json.getString(Provider.API_VERSION)+ "String_Node_Str"+ EIP.SERVICE_API_PATH;
      eip_service_json_string=downloadWithProviderCA(eip_service_url,last_danger_on);
      JSONObject eip_service_json=new JSONObject(eip_service_json_string);
      eip_service_json.getInt(Provider.API_RETURN_SERIAL);
      preferences.edit().putString(Constants.KEY,eip_service_json.toString()).commit();
      result.putBoolean(RESULT_KEY,true);
    }
 catch (    JSONException e) {
      String reason_to_fail=pickErrorMessage(eip_service_json_string);
      result.putString(ERRORS,reason_to_fail);
      result.putBoolean(RESULT_KEY,false);
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Downloads the eip-service.json from a given URL, and saves eip service capabilities including the offered gateways
 * @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the download was successful.
 */
@Override protected Bundle getAndSetEipServiceJson(){
  Bundle result=new Bundle();
  String eip_service_json_string="String_Node_Str";
  if (go_ahead) {
    try {
      JSONObject provider_json=new JSONObject(preferences.getString(Provider.KEY,"String_Node_Str"));
      String eip_service_url=provider_json.getString(Provider.API_URL) + "String_Node_Str" + provider_json.getString(Provider.API_VERSION)+ "String_Node_Str"+ EIP.SERVICE_API_PATH;
      eip_service_json_string=downloadWithProviderCA(eip_service_url,last_danger_on);
      JSONObject eip_service_json=new JSONObject(eip_service_json_string);
      eip_service_json.getInt(Provider.API_RETURN_SERIAL);
      preferences.edit().putString(Constants.KEY,eip_service_json.toString()).commit();
      result.putBoolean(RESULT_KEY,true);
    }
 catch (    NullPointerException|JSONException e) {
      String reason_to_fail=pickErrorMessage(eip_service_json_string);
      result.putString(ERRORS,reason_to_fail);
      result.putBoolean(RESULT_KEY,false);
    }
  }
  return result;
}
Program: 109659
Project: 109659
Buggy source:
public static boolean checkErroneousDownload(String downloaded_string){
  try {
    if (new JSONObject(downloaded_string).has(ProviderAPI.ERRORS) || downloaded_string.isEmpty()) {
      return true;
    }
 else {
      return false;
    }
  }
 catch (  JSONException e) {
    return false;
  }
}

Fixed version (ground truth):
public static boolean checkErroneousDownload(String downloaded_string){
  try {
    if (new JSONObject(downloaded_string).has(ProviderAPI.ERRORS) || downloaded_string.isEmpty()) {
      return true;
    }
 else {
      return false;
    }
  }
 catch (  NullPointerException|JSONException e) {
    return false;
  }
}
Program: 109660
Project: 109660
Buggy source:
private Bundle getAndSetProviderJson(String provider_main_url,String provider_ca_cert_fingerprint){
  Bundle result=new Bundle();
  if (go_ahead) {
    String provider_dot_json_string;
    if (provider_ca_cert_fingerprint.isEmpty())     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str");
 else     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str",provider_ca_cert_fingerprint);
    try {
      JSONObject provider_json=new JSONObject(provider_dot_json_string);
      provider_api_url=provider_json.getString(Provider.API_URL) + "String_Node_Str" + provider_json.getString(Provider.API_VERSION);
      String name=provider_json.getString(Provider.NAME);
      preferences.edit().putString(Provider.KEY,provider_json.toString()).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_ANON,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit();
      result.putBoolean(RESULT_KEY,true);
    }
 catch (    JSONException e) {
      String reason_to_fail=pickErrorMessage(provider_dot_json_string);
      result.putString(ERRORS,reason_to_fail);
      result.putBoolean(RESULT_KEY,false);
    }
  }
  return result;
}

Fixed version (ground truth):
private Bundle getAndSetProviderJson(String provider_main_url,String provider_ca_cert_fingerprint){
  Bundle result=new Bundle();
  if (go_ahead) {
    String provider_dot_json_string;
    if (provider_ca_cert_fingerprint.isEmpty())     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str");
 else     provider_dot_json_string=downloadWithCommercialCA(provider_main_url + "String_Node_Str",provider_ca_cert_fingerprint);
    if (!isValidJson(provider_dot_json_string)) {
      result.putString(ERRORS,getString(malformed_url));
      result.putBoolean(RESULT_KEY,false);
      return result;
    }
    try {
      JSONObject provider_json=new JSONObject(provider_dot_json_string);
      provider_api_url=provider_json.getString(Provider.API_URL) + "String_Node_Str" + provider_json.getString(Provider.API_VERSION);
      String name=provider_json.getString(Provider.NAME);
      preferences.edit().putString(Provider.KEY,provider_json.toString()).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_ANON,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit();
      preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED,provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit();
      result.putBoolean(RESULT_KEY,true);
    }
 catch (    JSONException e) {
      String reason_to_fail=pickErrorMessage(provider_dot_json_string);
      result.putString(ERRORS,reason_to_fail);
      result.putBoolean(RESULT_KEY,false);
    }
  }
  return result;
}