Source:
<code>public void startSignIn(@NonNull final IdpResponse response, @NonNull final String password) { if (!response.isSuccessful()) { setResult(Resource.<IdpResponse>forFailure(response.getError())); return; } if (!response.getProviderType().equals(EmailAuthProvider.PROVIDER_ID)) { throw new IllegalStateException( "This handler can only be used with the email provider"); } setResult(Resource.<IdpResponse>forLoading()); final String email = response.getEmail(); AnonymousUpgradeUtils.createUserWithEmailAndPasswordOrLink(getAuth(), getArguments(), email, password) .continueWithTask(new ProfileMerger(response)) .addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")) .addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult result) { handleSuccess(response, result); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (e instanceof FirebaseAuthUserCollisionException) { <START> if (AnonymousUpgradeUtils.canUpgradeAnonymous(getAuth(), <END> getArguments())) { AuthCredential credential = EmailAuthProvider.getCredential(email, password); IdpResponse failureResponse = new IdpResponse.Builder(credential) .build(); setResult(Resource.<IdpResponse>forFailure(new FirebaseAuthAnonymousUpgradeException( ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, failureResponse))); } else { ProviderUtils.fetchTopProvider(getAuth(), email) .addOnSuccessListener(new StartWelcomeBackFlow(email)) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { setResult(Resource.<IdpResponse>forFailure(e)); } }); } } else { setResult(Resource.<IdpResponse>forFailure(e)); } } }); }</code><technical_language>instead of overloading this branch createOrLink method transform collision errors a custom error class a Continuation</technical_language>

Target:
public void startSignIn(@NonNull final IdpResponse response, @NonNull final String password) { if (!response.isSuccessful()) { setResult(Resource.<IdpResponse>forFailure(response.getError())); return; } if (!response.getProviderType().equals(EmailAuthProvider.PROVIDER_ID)) { throw new IllegalStateException( "This handler can only be used with the email provider"); } setResult(Resource.<IdpResponse>forLoading()); final AuthOperationManager authOperationManager = AuthOperationManager.getInstance(); final String email = response.getEmail(); authOperationManager.createOrLinkUserWithEmailAndPassword(getAuth(), getArguments(), email, password) .continueWithTask(new ProfileMerger(response)) .addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")) .addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult result) { handleSuccess(response, result); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (e instanceof FirebaseAuthUserCollisionException) { if (authOperationManager.canUpgradeAnonymous(getAuth(), getArguments())) { AuthCredential credential = EmailAuthProvider.getCredential(email, password); handleMergeFailure(credential); } else { ProviderUtils.fetchTopProvider(getAuth(), email) .addOnSuccessListener(new StartWelcomeBackFlow(email)) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { setResult(Resource.<IdpResponse>forFailure(e)); } }); } } else { setResult(Resource.<IdpResponse>forFailure(e)); } } }); }