Program: 35582
Project: 35582
Buggy source:
@Override protected void onAttach(@NonNull View view){
  super.onAttach(view);
  if (getActionBar() != null) {
    getActionBar().show();
  }
  dispose(null);
  userEntity=userUtils.getCurrentUser();
  if (!TextUtils.isEmpty(userEntity.getClientCertificate())) {
    certificateSetup.setTitle(R.string.nc_client_cert_change);
  }
 else {
    certificateSetup.setTitle(R.string.nc_client_cert_setup);
  }
  if ("String_Node_Str".equals(appPreferences.getProxyType()) || appPreferences.getProxyType() == null) {
    hideProxySettings();
  }
 else {
    showProxySettings();
  }
  if (appPreferences.getProxyCredentials()) {
    showProxyCredentials();
  }
 else {
    hideProxyCredentials();
  }
  if (userEntity != null) {
    baseUrlTextView.setText(userEntity.getBaseUrl());
    reauthorizeButton.addPreferenceClickListener(view14 -> {
      getParentController().getRouter().pushController(RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(),true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler()));
    }
);
    if (userEntity.getDisplayName() != null) {
      displayNameTextView.setText(userEntity.getDisplayName());
    }
    loadAvatarImage();
    profileQueryDisposable=ncApi.getUserProfile(ApiUtils.getCredentials(userEntity.getUsername(),userEntity.getToken()),ApiUtils.getUrlForUserProfile(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(userProfileOverall -> {
      String displayName=null;
      if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getDisplayName())) {
        displayName=userProfileOverall.getOcs().getData().getDisplayName();
      }
 else       if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getDisplayNameAlt())) {
        displayName=userProfileOverall.getOcs().getData().getDisplayNameAlt();
      }
      boolean needsToUpdateUserId=!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getUserId()) && !userProfileOverall.getOcs().getData().getUserId().equals(userEntity.getUserId());
      if ((!TextUtils.isEmpty(displayName) && !displayName.equals(userEntity.getDisplayName())) || needsToUpdateUserId) {
        dbQueryDisposable=userUtils.createOrUpdateUser(null,null,null,displayName,null,null,userProfileOverall.getOcs().getData().getUserId(),userEntity.getId(),null,null).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(userEntityResult -> {
          displayNameTextView.setText(userEntityResult.getDisplayName());
          if (needsToUpdateUserId) {
            loadAvatarImage();
          }
        }
,throwable -> {
          dispose(dbQueryDisposable);
        }
,() -> dispose(dbQueryDisposable));
      }
    }
,throwable -> {
      dispose(profileQueryDisposable);
    }
,() -> dispose(profileQueryDisposable));
    removeAccountButton.addPreferenceClickListener(view1 -> {
      cookieManager.getCookieStore().removeAll();
      boolean otherUserExists=userUtils.scheduleUserForDeletionWithId(userEntity.getId());
      new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true).startNow().build().scheduleAsync();
      if (otherUserExists && getView() != null) {
        onViewBound(getView());
        onAttach(getView());
      }
 else       if (!otherUserExists) {
        if (getParentController() == null || getParentController().getRouter() == null) {
          if (getActivity() != null) {
            getActivity().finish();
          }
        }
 else {
          getParentController().getRouter().setRoot(RouterTransaction.with(new ServerSelectionController()).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler()));
        }
      }
    }
);
  }
  if (userUtils.getUsers().size() <= 1) {
    switchAccountButton.setVisibility(View.GONE);
  }
  if (ApplicationWideMessageHolder.getInstance().getMessageType() != null) {
switch (ApplicationWideMessageHolder.getInstance().getMessageType()) {
case ACCOUNT_UPDATED_NOT_ADDED:
      messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
    messageText.setText(getResources().getString(R.string.nc_settings_account_updated));
  messageView.setVisibility(View.VISIBLE);
break;
case WRONG_ACCOUNT:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
messageView.setVisibility(View.VISIBLE);
break;
case SERVER_WITHOUT_TALK:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
messageView.setVisibility(View.VISIBLE);
case ACCOUNT_WAS_IMPORTED:
messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
messageText.setText(getResources().getString(R.string.nc_Server_account_imported));
messageView.setVisibility(View.VISIBLE);
break;
case FAILED_TO_IMPORT_ACCOUNT:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_server_failed_to_import_account));
messageView.setVisibility(View.VISIBLE);
break;
default :
messageView.setVisibility(View.GONE);
break;
}
ApplicationWideMessageHolder.getInstance().setMessageType(null);
messageView.animate().translationY(0).alpha(0.0f).setDuration(2500).setStartDelay(5000).setListener(new AnimatorListenerAdapter(){
@Override public void onAnimationEnd(Animator animation){
super.onAnimationEnd(animation);
if (messageView != null) {
messageView.setVisibility(View.GONE);
}
}
}
);
}
 else {
if (messageView != null) {
messageView.setVisibility(View.GONE);
}
}
}

Fixed version (ground truth):
@Override protected void onAttach(@NonNull View view){
  super.onAttach(view);
  if (getActionBar() != null) {
    getActionBar().show();
  }
  dispose(null);
  userEntity=userUtils.getCurrentUser();
  if (!TextUtils.isEmpty(userEntity.getClientCertificate())) {
    certificateSetup.setTitle(R.string.nc_client_cert_change);
  }
 else {
    certificateSetup.setTitle(R.string.nc_client_cert_setup);
  }
  if ("String_Node_Str".equals(appPreferences.getProxyType()) || appPreferences.getProxyType() == null) {
    hideProxySettings();
  }
 else {
    showProxySettings();
  }
  if (appPreferences.getProxyCredentials()) {
    showProxyCredentials();
  }
 else {
    hideProxyCredentials();
  }
  if (userEntity != null) {
    baseUrlTextView.setText(userEntity.getBaseUrl());
    reauthorizeButton.addPreferenceClickListener(view14 -> {
      getParentController().getRouter().pushController(RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(),true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler()));
    }
);
    if (userEntity.getDisplayName() != null) {
      displayNameTextView.setText(userEntity.getDisplayName());
    }
    loadAvatarImage();
    profileQueryDisposable=ncApi.getUserProfile(ApiUtils.getCredentials(userEntity.getUsername(),userEntity.getToken()),ApiUtils.getUrlForUserProfile(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(userProfileOverall -> {
      String displayName=null;
      if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getDisplayName())) {
        displayName=userProfileOverall.getOcs().getData().getDisplayName();
      }
 else       if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getDisplayNameAlt())) {
        displayName=userProfileOverall.getOcs().getData().getDisplayNameAlt();
      }
      if ((!TextUtils.isEmpty(displayName) && !displayName.equals(userEntity.getDisplayName()))) {
        dbQueryDisposable=userUtils.createOrUpdateUser(null,null,null,displayName,null,null,null,userEntity.getId(),null,null).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(userEntityResult -> {
          displayNameTextView.setText(userEntityResult.getDisplayName());
        }
,throwable -> {
          dispose(dbQueryDisposable);
        }
,() -> dispose(dbQueryDisposable));
      }
    }
,throwable -> {
      dispose(profileQueryDisposable);
    }
,() -> dispose(profileQueryDisposable));
    removeAccountButton.addPreferenceClickListener(view1 -> {
      cookieManager.getCookieStore().removeAll();
      boolean otherUserExists=userUtils.scheduleUserForDeletionWithId(userEntity.getId());
      new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true).startNow().build().scheduleAsync();
      if (otherUserExists && getView() != null) {
        onViewBound(getView());
        onAttach(getView());
      }
 else       if (!otherUserExists) {
        if (getParentController() == null || getParentController().getRouter() == null) {
          if (getActivity() != null) {
            getActivity().finish();
          }
        }
 else {
          getParentController().getRouter().setRoot(RouterTransaction.with(new ServerSelectionController()).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler()));
        }
      }
    }
);
  }
  if (userUtils.getUsers().size() <= 1) {
    switchAccountButton.setVisibility(View.GONE);
  }
  if (ApplicationWideMessageHolder.getInstance().getMessageType() != null) {
switch (ApplicationWideMessageHolder.getInstance().getMessageType()) {
case ACCOUNT_UPDATED_NOT_ADDED:
      messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
    messageText.setText(getResources().getString(R.string.nc_settings_account_updated));
  messageView.setVisibility(View.VISIBLE);
break;
case WRONG_ACCOUNT:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
messageView.setVisibility(View.VISIBLE);
break;
case SERVER_WITHOUT_TALK:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
messageView.setVisibility(View.VISIBLE);
case ACCOUNT_WAS_IMPORTED:
messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
messageText.setText(getResources().getString(R.string.nc_Server_account_imported));
messageView.setVisibility(View.VISIBLE);
break;
case FAILED_TO_IMPORT_ACCOUNT:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_server_failed_to_import_account));
messageView.setVisibility(View.VISIBLE);
break;
default :
messageView.setVisibility(View.GONE);
break;
}
ApplicationWideMessageHolder.getInstance().setMessageType(null);
messageView.animate().translationY(0).alpha(0.0f).setDuration(2500).setStartDelay(5000).setListener(new AnimatorListenerAdapter(){
@Override public void onAnimationEnd(Animator animation){
super.onAnimationEnd(animation);
if (messageView != null) {
messageView.setVisibility(View.GONE);
}
}
}
);
}
 else {
if (messageView != null) {
messageView.setVisibility(View.GONE);
}
}
}