Source:
<code>private void handleAnonymousUpgradeFlow(final FirebaseAuth auth, final HelperActivityBase activity, final OAuthProvider provider, final FlowParameters flowParameters) { auth.getCurrentUser() .startActivityForLinkWithProvider(activity, provider) .addOnSuccessListener( new OnSuccessListener<AuthResult>() { @Override public void onSuccess(@NonNull AuthResult authResult) { FirebaseUser user = authResult.getUser(); <START> IdpResponse idpResponse = new IdpResponse.Builder( <END> new User.Builder(provider.getProviderId(), user.getEmail()) .setName(user.getDisplayName()) .setPhotoUri(user.getPhotoUrl()) .build()) .build(); setResult(Resource.<IdpResponse>forSuccess(idpResponse)); } }) .addOnFailureListener( new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (e instanceof FirebaseAuthUserCollisionException) { final AuthCredential credential = ((FirebaseAuthUserCollisionException) e) .getUpdatedCredential(); final String email = ((FirebaseAuthUserCollisionException) e).getEmail(); ProviderUtils.fetchSortedProviders(auth, flowParameters, email) .addOnSuccessListener(new OnSuccessListener<List<String>>() { @Override public void onSuccess(List<String> providers) { if (providers.isEmpty()) { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException( ErrorCodes.DEVELOPER_ERROR, "No supported providers."))); return; } if (providers.contains(provider.getProviderId())) { handleMergeFailure(credential); } else { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiUserCollisionException( ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR, "Recoverable error.", provider.getProviderId(), email, credential))); } } }); } else { setResult(Resource.<IdpResponse>forFailure(e)); } } }); }</code><technical_language>Nit: this response-from-user code block is repeated could/should pulled out a helper</technical_language>

Target:
private void handleAnonymousUpgradeFlow(final FirebaseAuth auth, final HelperActivityBase activity, final OAuthProvider provider, final FlowParameters flowParameters) { auth.getCurrentUser() .startActivityForLinkWithProvider(activity, provider) .addOnSuccessListener( new OnSuccessListener<AuthResult>() { @Override public void onSuccess(@NonNull AuthResult authResult) { handleSuccess(provider.getProviderId(), authResult.getUser(), (OAuthCredential) authResult.getCredential()); } }) .addOnFailureListener( new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (!(e instanceof FirebaseAuthUserCollisionException)) { setResult(Resource.<IdpResponse>forFailure(e)); return; } FirebaseAuthUserCollisionException collisionException = (FirebaseAuthUserCollisionException) e; final AuthCredential credential = collisionException.getUpdatedCredential(); final String email = collisionException.getEmail(); ProviderUtils.fetchSortedProviders(auth, flowParameters, email) .addOnSuccessListener(new OnSuccessListener<List<String>>() { @Override public void onSuccess(List<String> providers) { if (providers.isEmpty()) { String errorMessage = "Unable to complete the linkingflow -" + " the user is using " + "unsupported providers."; setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException( ErrorCodes.DEVELOPER_ERROR, errorMessage))); return; } if (providers.contains(provider.getProviderId())) { handleMergeFailure(credential); } else { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiUserCollisionException( ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR, "Recoverable error.", provider.getProviderId(), email, credential))); } } }); } }); }