Program: 142236
Project: 142236
Buggy source:
@Override protected void onActivityResult(int requestCode,int resultCode,Intent intent){
  if (resultCode == RESULT_RESTART) {
    startNextFetch();
    return;
  }
  try {
switch (requestCode) {
case INIT_APP:
      if (resultCode == RESULT_CANCELED) {
        this.finish();
        return;
      }
 else       if (resultCode == RESULT_OK) {
        configUi();
        return;
      }
    break;
case UPGRADE_APP:
  if (resultCode == RESULT_CANCELED) {
    return;
  }
 else   if (resultCode == RESULT_OK) {
    if (intent.getBooleanExtra(CommCareSetupActivity.KEY_REQUIRE_REFRESH,true)) {
      Toast.makeText(this,Localization.get("String_Node_Str"),Toast.LENGTH_LONG).show();
      CommCareApplication._().getSession().startLogout();
    }
    SharedPreferences preferences=CommCareApplication._().getCurrentApp().getAppPreferences();
    preferences.edit().putBoolean(CommCarePreferences.AUTO_TRIGGER_UPDATE,true);
    return;
  }
break;
case PREFERENCES_ACTIVITY:
configUi();
return;
case MISSING_MEDIA_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
this.finish();
return;
}
 else if (resultCode == RESULT_OK) {
Toast.makeText(this,"String_Node_Str",Toast.LENGTH_LONG).show();
return;
}
case DUMP_FORMS_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
return;
}
 else if (resultCode == DumpTask.BULK_DUMP_ID) {
int dumpedCount=intent.getIntExtra(CommCareFormDumpActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,false);
refreshView();
return;
}
 else if (resultCode == SendTask.BULK_SEND_ID) {
int dumpedCount=intent.getIntExtra(CommCareFormDumpActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,true);
Toast.makeText(this,Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),Toast.LENGTH_LONG).show();
refreshView();
return;
}
case CONNECTION_DIAGNOSTIC_ACTIVITY:
return;
case WIFI_DIRECT_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
return;
}
 else if (resultCode == SendTask.BULK_SEND_ID) {
int dumpedCount=intent.getIntExtra(CommCareWiFiDirectActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,true);
Toast.makeText(this,"String_Node_Str",Toast.LENGTH_LONG).show();
refreshView();
return;
}
 else if (resultCode == WipeTask.WIPE_TASK_ID) {
int dumpedCount=intent.getIntExtra(CommCareWiFiDirectActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,true);
Toast.makeText(this,"String_Node_Str",Toast.LENGTH_LONG).show();
refreshView();
return;
}
case REPORT_PROBLEM_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
return;
}
 else if (resultCode == RESULT_OK) {
CommCareApplication._().notifyLogsPending();
refreshView();
return;
}
case LOGIN_USER:
if (resultCode == RESULT_CANCELED) {
this.finish();
return;
}
 else if (resultCode == RESULT_OK) {
if (intent.getBooleanExtra(LoginActivity.ALREADY_LOGGED_IN,false)) {
}
 else {
refreshView();
checkAndStartUnsentTask(false);
if (isDemoUser()) {
showDemoModeWarning();
}
}
return;
}
break;
case GET_INCOMPLETE_FORM:
AndroidSessionWrapper currentState=CommCareApplication._().getCurrentSessionWrapper();
if (resultCode == RESULT_CANCELED) {
refreshView();
return;
}
 else if (resultCode == RESULT_OK) {
int record=intent.getIntExtra("String_Node_Str",-1);
if (record == -1) {
break;
}
FormRecord r=CommCareApplication._().getUserStorage(FormRecord.class).read(record);
SqlStorage<SessionStateDescriptor> ssdStorage=CommCareApplication._().getUserStorage(SessionStateDescriptor.class);
Vector<Integer> ssds=ssdStorage.getIDsForValue(SessionStateDescriptor.META_FORM_RECORD_ID,r.getID());
if (ssds.size() == 1) {
currentState.loadFromStateDescription(ssdStorage.read(ssds.firstElement()));
}
 else {
currentState.setFormRecordId(r.getID());
}
formEntry(platform.getFormContentUri(r.getFormNamespace()),r);
return;
}
break;
case GET_COMMAND:
currentState=CommCareApplication._().getCurrentSessionWrapper();
if (resultCode == RESULT_CANCELED) {
if (currentState.getSession().getCommand() == null) {
currentState.reset();
refreshView();
return;
}
 else {
currentState.getSession().stepBack();
break;
}
}
 else if (resultCode == RESULT_OK) {
String command=intent.getStringExtra(SessionFrame.STATE_COMMAND_ID);
currentState.getSession().setCommand(command);
break;
}
break;
case GET_CASE:
currentState=CommCareApplication._().getCurrentSessionWrapper();
if (resultCode == RESULT_CANCELED) {
currentState.getSession().stepBack();
break;
}
 else if (resultCode == RESULT_OK) {
currentState.getSession().setDatum(currentState.getSession().getNeededDatum().getDataId(),intent.getStringExtra(SessionFrame.STATE_DATUM_VAL));
if (intent.hasExtra(CallOutActivity.CALL_DURATION)) {
platform.setCallDuration(intent.getLongExtra(CallOutActivity.CALL_DURATION,0));
}
break;
}
case MODEL_RESULT:
if (!CommCareApplication._().getSession().isLoggedIn()) {
CommCareApplication._().getCurrentSessionWrapper().reset();
returnToLogin();
}
 else {
processReturnFromFormEntry(resultCode,intent);
}
break;
}
startNextFetch();
}
 catch (SessionUnavailableException sue) {
returnToLogin();
}
super.onActivityResult(requestCode,resultCode,intent);
}

Fixed version (ground truth):
@Override protected void onActivityResult(int requestCode,int resultCode,Intent intent){
  if (resultCode == RESULT_RESTART) {
    startNextFetch();
    return;
  }
  try {
switch (requestCode) {
case INIT_APP:
      if (resultCode == RESULT_CANCELED) {
        this.finish();
        return;
      }
 else       if (resultCode == RESULT_OK) {
        configUi();
        return;
      }
    break;
case UPGRADE_APP:
  if (resultCode == RESULT_CANCELED) {
    return;
  }
 else   if (resultCode == RESULT_OK) {
    if (intent.getBooleanExtra(CommCareSetupActivity.KEY_REQUIRE_REFRESH,true)) {
      Toast.makeText(this,Localization.get("String_Node_Str"),Toast.LENGTH_LONG).show();
      CommCareApplication._().logout();
    }
    SharedPreferences preferences=CommCareApplication._().getCurrentApp().getAppPreferences();
    preferences.edit().putBoolean(CommCarePreferences.AUTO_TRIGGER_UPDATE,true);
    return;
  }
break;
case PREFERENCES_ACTIVITY:
configUi();
return;
case MISSING_MEDIA_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
this.finish();
return;
}
 else if (resultCode == RESULT_OK) {
Toast.makeText(this,"String_Node_Str",Toast.LENGTH_LONG).show();
return;
}
case DUMP_FORMS_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
return;
}
 else if (resultCode == DumpTask.BULK_DUMP_ID) {
int dumpedCount=intent.getIntExtra(CommCareFormDumpActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,false);
refreshView();
return;
}
 else if (resultCode == SendTask.BULK_SEND_ID) {
int dumpedCount=intent.getIntExtra(CommCareFormDumpActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,true);
Toast.makeText(this,Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),Toast.LENGTH_LONG).show();
refreshView();
return;
}
case CONNECTION_DIAGNOSTIC_ACTIVITY:
return;
case WIFI_DIRECT_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
return;
}
 else if (resultCode == SendTask.BULK_SEND_ID) {
int dumpedCount=intent.getIntExtra(CommCareWiFiDirectActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,true);
Toast.makeText(this,"String_Node_Str",Toast.LENGTH_LONG).show();
refreshView();
return;
}
 else if (resultCode == WipeTask.WIPE_TASK_ID) {
int dumpedCount=intent.getIntExtra(CommCareWiFiDirectActivity.KEY_NUMBER_DUMPED,-1);
displayMessage(Localization.get("String_Node_Str",new String[]{"String_Node_Str" + dumpedCount}),false,true);
Toast.makeText(this,"String_Node_Str",Toast.LENGTH_LONG).show();
refreshView();
return;
}
case REPORT_PROBLEM_ACTIVITY:
if (resultCode == RESULT_CANCELED) {
return;
}
 else if (resultCode == RESULT_OK) {
CommCareApplication._().notifyLogsPending();
refreshView();
return;
}
case LOGIN_USER:
if (resultCode == RESULT_CANCELED) {
this.finish();
return;
}
 else if (resultCode == RESULT_OK) {
if (intent.getBooleanExtra(LoginActivity.ALREADY_LOGGED_IN,false)) {
}
 else {
refreshView();
checkAndStartUnsentTask(false);
if (isDemoUser()) {
showDemoModeWarning();
}
}
return;
}
break;
case GET_INCOMPLETE_FORM:
AndroidSessionWrapper currentState=CommCareApplication._().getCurrentSessionWrapper();
if (resultCode == RESULT_CANCELED) {
refreshView();
return;
}
 else if (resultCode == RESULT_OK) {
int record=intent.getIntExtra("String_Node_Str",-1);
if (record == -1) {
break;
}
FormRecord r=CommCareApplication._().getUserStorage(FormRecord.class).read(record);
SqlStorage<SessionStateDescriptor> ssdStorage=CommCareApplication._().getUserStorage(SessionStateDescriptor.class);
Vector<Integer> ssds=ssdStorage.getIDsForValue(SessionStateDescriptor.META_FORM_RECORD_ID,r.getID());
if (ssds.size() == 1) {
currentState.loadFromStateDescription(ssdStorage.read(ssds.firstElement()));
}
 else {
currentState.setFormRecordId(r.getID());
}
formEntry(platform.getFormContentUri(r.getFormNamespace()),r);
return;
}
break;
case GET_COMMAND:
currentState=CommCareApplication._().getCurrentSessionWrapper();
if (resultCode == RESULT_CANCELED) {
if (currentState.getSession().getCommand() == null) {
currentState.reset();
refreshView();
return;
}
 else {
currentState.getSession().stepBack();
break;
}
}
 else if (resultCode == RESULT_OK) {
String command=intent.getStringExtra(SessionFrame.STATE_COMMAND_ID);
currentState.getSession().setCommand(command);
break;
}
break;
case GET_CASE:
currentState=CommCareApplication._().getCurrentSessionWrapper();
if (resultCode == RESULT_CANCELED) {
currentState.getSession().stepBack();
break;
}
 else if (resultCode == RESULT_OK) {
currentState.getSession().setDatum(currentState.getSession().getNeededDatum().getDataId(),intent.getStringExtra(SessionFrame.STATE_DATUM_VAL));
if (intent.hasExtra(CallOutActivity.CALL_DURATION)) {
platform.setCallDuration(intent.getLongExtra(CallOutActivity.CALL_DURATION,0));
}
break;
}
case MODEL_RESULT:
if (!CommCareApplication._().getSession().isLoggedIn()) {
CommCareApplication._().getCurrentSessionWrapper().reset();
returnToLogin();
}
 else {
processReturnFromFormEntry(resultCode,intent);
}
break;
}
startNextFetch();
}
 catch (SessionUnavailableException sue) {
returnToLogin();
}
super.onActivityResult(requestCode,resultCode,intent);
}