Program: 142315
Project: 142315
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  editProfileRef=(EditText)this.findViewById(R.id.edit_profile_location);
  advancedView=this.findViewById(R.id.advanced_panel);
  mainMessage=(TextView)this.findViewById(R.id.str_setup_message);
  urlSpinner=(Spinner)this.findViewById(R.id.url_spinner);
  installButton=(Button)this.findViewById(R.id.start_install);
  mScanBarcodeButton=(Button)this.findViewById(R.id.btn_fetch_uri);
  addressEntryButton=(Button)this.findViewById(R.id.enter_app_location);
  startOverButton=(Button)this.findViewById(R.id.start_over);
  retryButton=(Button)this.findViewById(R.id.retry_install);
  if (savedInstanceState == null) {
    incomingRef=this.getIntent().getStringExtra(KEY_PROFILE_REF);
    upgradeMode=this.getIntent().getBooleanExtra(KEY_UPGRADE_MODE,false);
    isAuto=this.getIntent().getBooleanExtra(KEY_AUTO,false);
  }
 else {
    String uiStateEncoded=savedInstanceState.getString("String_Node_Str");
    this.uiState=uiStateEncoded == null ? UiState.basic : UiState.valueOf(UiState.class,uiStateEncoded);
    incomingRef=savedInstanceState.getString("String_Node_Str");
    upgradeMode=savedInstanceState.getBoolean(KEY_UPGRADE_MODE);
    isAuto=savedInstanceState.getBoolean(KEY_AUTO);
    startAllowed=savedInstanceState.getBoolean("String_Node_Str");
  }
  editProfileRef.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
  urlSpinner.setAdapter(new WrappingSpinnerAdapter(urlSpinner.getAdapter(),getResources().getStringArray(R.array.url_list_selected_display)));
  urlVals=getResources().getStringArray(R.array.url_vals);
  retryButton.setText(Localization.get("String_Node_Str"));
  installButton.setText(Localization.get("String_Node_Str"));
  urlSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> arg0,    View arg1,    int arg2,    long arg3){
      if ((previousUrlPosition == 0 || previousUrlPosition == 1) && arg2 == 2) {
        editProfileRef.setText(R.string.default_app_server);
      }
 else       if (previousUrlPosition == 2 && (arg2 == 0 || arg2 == 1)) {
        editProfileRef.setText("String_Node_Str");
      }
      previousUrlPosition=arg2;
    }
    @Override public void onNothingSelected(    AdapterView<?> arg0){
    }
  }
);
  dbState=CommCareApplication._().getDatabaseState();
  resourceState=CommCareApplication._().getAppResourceState();
  if (Intent.ACTION_VIEW.equals(this.getIntent().getAction())) {
    incomingRef=this.getIntent().getData().toString();
  }
 else {
    if (dbState == CommCareApplication.STATE_READY && resourceState == CommCareApplication.STATE_READY && !upgradeMode) {
      Intent i=new Intent(getIntent());
      setResult(RESULT_OK,i);
      finish();
      return;
    }
  }
  mScanBarcodeButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      try {
        Intent i=new Intent("String_Node_Str");
        i.putExtra("String_Node_Str","String_Node_Str");
        CommCareSetupActivity.this.startActivityForResult(i,BARCODE_CAPTURE);
      }
 catch (      ActivityNotFoundException e) {
        Toast.makeText(CommCareSetupActivity.this,"String_Node_Str",Toast.LENGTH_SHORT).show();
        mScanBarcodeButton.setVisibility(View.GONE);
      }
    }
  }
);
  addressEntryButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      setModeToAdvanced();
    }
  }
);
  addressEntryButton.setText(Localization.get("String_Node_Str"));
  startOverButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      if (upgradeMode) {
        startResourceInstall(true);
      }
 else {
        retryCount=0;
        partialMode=false;
        setModeToBasic();
      }
    }
  }
);
  startOverButton.setText(Localization.get("String_Node_Str"));
  retryButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      if (!upgradeMode) {
        partialMode=true;
      }
      startResourceInstall(false);
    }
  }
);
  if (incomingRef == null || uiState == UiState.advanced) {
    editProfileRef.setText("String_Node_Str");
    if (this.uiState == UiState.advanced) {
      this.setModeToAdvanced();
    }
 else {
      this.setModeToBasic();
    }
  }
 else {
    this.setModeToReady(incomingRef);
  }
  installButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      if (dbState == CommCareApplication.STATE_READY) {
      }
      if (resourceState == CommCareApplication.STATE_READY) {
        if (!upgradeMode) {
          fail(NotificationMessageFactory.message(ResourceEngineOutcomes.StatusFailState),true);
        }
      }
 else       if (resourceState == CommCareApplication.STATE_UNINSTALLED) {
        startResourceInstall();
      }
 else       if (resourceState == CommCareApplication.STATE_UPGRADE && upgradeMode) {
        startResourceInstall();
      }
    }
  }
);
  banner=this.findViewById(R.id.screen_first_start_banner);
  final View activityRootView=findViewById(R.id.screen_first_start_main);
  activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
    @Override public void onGlobalLayout(){
      int hideAll=CommCareSetupActivity.this.getResources().getInteger(R.integer.login_screen_hide_all_cuttoff);
      int hideBanner=CommCareSetupActivity.this.getResources().getInteger(R.integer.login_screen_hide_banner_cuttoff);
      int height=activityRootView.getHeight();
      if (height < hideAll) {
        banner.setVisibility(View.GONE);
      }
 else       if (height < hideBanner) {
        banner.setVisibility(View.GONE);
      }
 else {
        banner.setVisibility(View.VISIBLE);
      }
    }
  }
);
  findViewById(R.id.mainLayout).requestFocus();
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  CommCareSetupActivity oldActivity=(CommCareSetupActivity)this.getDestroyedActivityState();
  editProfileRef=(EditText)this.findViewById(R.id.edit_profile_location);
  advancedView=this.findViewById(R.id.advanced_panel);
  mainMessage=(TextView)this.findViewById(R.id.str_setup_message);
  urlSpinner=(Spinner)this.findViewById(R.id.url_spinner);
  installButton=(Button)this.findViewById(R.id.start_install);
  mScanBarcodeButton=(Button)this.findViewById(R.id.btn_fetch_uri);
  addressEntryButton=(Button)this.findViewById(R.id.enter_app_location);
  startOverButton=(Button)this.findViewById(R.id.start_over);
  retryButton=(Button)this.findViewById(R.id.retry_install);
  if (savedInstanceState == null) {
    incomingRef=this.getIntent().getStringExtra(KEY_PROFILE_REF);
    upgradeMode=this.getIntent().getBooleanExtra(KEY_UPGRADE_MODE,false);
    isAuto=this.getIntent().getBooleanExtra(KEY_AUTO,false);
  }
 else {
    String uiStateEncoded=savedInstanceState.getString("String_Node_Str");
    this.uiState=uiStateEncoded == null ? UiState.basic : UiState.valueOf(UiState.class,uiStateEncoded);
    incomingRef=savedInstanceState.getString("String_Node_Str");
    upgradeMode=savedInstanceState.getBoolean(KEY_UPGRADE_MODE);
    isAuto=savedInstanceState.getBoolean(KEY_AUTO);
    startAllowed=savedInstanceState.getBoolean("String_Node_Str");
  }
  editProfileRef.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
  urlSpinner.setAdapter(new WrappingSpinnerAdapter(urlSpinner.getAdapter(),getResources().getStringArray(R.array.url_list_selected_display)));
  urlVals=getResources().getStringArray(R.array.url_vals);
  retryButton.setText(Localization.get("String_Node_Str"));
  installButton.setText(Localization.get("String_Node_Str"));
  urlSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> arg0,    View arg1,    int arg2,    long arg3){
      if ((previousUrlPosition == 0 || previousUrlPosition == 1) && arg2 == 2) {
        editProfileRef.setText(R.string.default_app_server);
      }
 else       if (previousUrlPosition == 2 && (arg2 == 0 || arg2 == 1)) {
        editProfileRef.setText("String_Node_Str");
      }
      previousUrlPosition=arg2;
    }
    @Override public void onNothingSelected(    AdapterView<?> arg0){
    }
  }
);
  dbState=CommCareApplication._().getDatabaseState();
  resourceState=CommCareApplication._().getAppResourceState();
  if (Intent.ACTION_VIEW.equals(this.getIntent().getAction())) {
    incomingRef=this.getIntent().getData().toString();
  }
 else {
    if (dbState == CommCareApplication.STATE_READY && resourceState == CommCareApplication.STATE_READY && !upgradeMode) {
      Intent i=new Intent(getIntent());
      setResult(RESULT_OK,i);
      finish();
      return;
    }
  }
  mScanBarcodeButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      try {
        Intent i=new Intent("String_Node_Str");
        i.putExtra("String_Node_Str","String_Node_Str");
        CommCareSetupActivity.this.startActivityForResult(i,BARCODE_CAPTURE);
      }
 catch (      ActivityNotFoundException e) {
        Toast.makeText(CommCareSetupActivity.this,"String_Node_Str",Toast.LENGTH_SHORT).show();
        mScanBarcodeButton.setVisibility(View.GONE);
      }
    }
  }
);
  addressEntryButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      setModeToAdvanced();
    }
  }
);
  addressEntryButton.setText(Localization.get("String_Node_Str"));
  startOverButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      if (upgradeMode) {
        startResourceInstall(true);
      }
 else {
        retryCount=0;
        partialMode=false;
        setModeToBasic();
      }
    }
  }
);
  startOverButton.setText(Localization.get("String_Node_Str"));
  retryButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      if (!upgradeMode) {
        partialMode=true;
      }
      startResourceInstall(false);
    }
  }
);
  if (incomingRef == null || uiState == UiState.advanced) {
    editProfileRef.setText("String_Node_Str");
    if (this.uiState == UiState.advanced) {
      this.setModeToAdvanced();
    }
 else {
      this.setModeToBasic();
    }
  }
 else {
    this.setModeToReady(incomingRef);
  }
  installButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      if (dbState == CommCareApplication.STATE_READY) {
      }
      if (resourceState == CommCareApplication.STATE_READY) {
        if (!upgradeMode) {
          fail(NotificationMessageFactory.message(ResourceEngineOutcomes.StatusFailState),true);
        }
      }
 else       if (resourceState == CommCareApplication.STATE_UNINSTALLED) {
        startResourceInstall();
      }
 else       if (resourceState == CommCareApplication.STATE_UPGRADE && upgradeMode) {
        startResourceInstall();
      }
    }
  }
);
  banner=this.findViewById(R.id.screen_first_start_banner);
  final View activityRootView=findViewById(R.id.screen_first_start_main);
  activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
    @Override public void onGlobalLayout(){
      int hideAll=CommCareSetupActivity.this.getResources().getInteger(R.integer.login_screen_hide_all_cuttoff);
      int hideBanner=CommCareSetupActivity.this.getResources().getInteger(R.integer.login_screen_hide_banner_cuttoff);
      int height=activityRootView.getHeight();
      if (height < hideAll) {
        banner.setVisibility(View.GONE);
      }
 else       if (height < hideBanner) {
        banner.setVisibility(View.GONE);
      }
 else {
        banner.setVisibility(View.VISIBLE);
      }
    }
  }
);
  if (oldActivity != null) {
    this.ccApp=oldActivity.ccApp;
  }
  findViewById(R.id.mainLayout).requestFocus();
}