[Demonstration 1]

[Buggy Method]
private void signIn(String email, String password) {
    mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            showProgress(false);
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful()) {
                Toast.makeText(LoginActivity.this, R.string.auth_failed, Toast.LENGTH_SHORT).show();
                mEmailView.setError(getString(R.string.error_invalid_email));
                mEmailView.requestFocus();
                mPasswordView.setError(getString(R.string.error_incorrect_password));
                mPasswordView.requestFocus();
            } else {
                // Sign user in with email
                mFirebaseDatabase.child(mAuth.getCurrentUser().getDisplayName()).addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        User user = dataSnapshot.getValue(User.class);
                        String accountType = user.accountType;
                        Intent mainActivity = new Intent(getApplicationContext(), MainActivity.class);
                        mainActivity.putExtra("ACCOUNT_TYPE", accountType);
                        startActivity(mainActivity);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        System.out.println("The read failed: " + databaseError.getCode());
                    }
                });
            }
        }
    });
}

[Buggy Hunk]
mFirebaseDatabase.child(mAuth.getCurrentUser().getDisplayName()).addListenerForSingleValueEvent(new ValueEventListener() {

[Patch]
mFirebaseDatabase.child(mAuth.getCurrentUser().getDisplayName()).addValueEventListener(new ValueEventListener() {

[Demonstration 2]

[Buggy Method]
private void submitActivator(ActivatorModel activatorModel) {
    CompletableFuture<Void> future = submit(() -> {
        try {
            return activatorModel.call();
        } catch (Throwable e) {
            error("Activator: " + activatorModel.getID() + " crashed", e);
            return true;
        }
    }).thenAccept(restart -> {
        if (restart != null && !restart) {
            debug("Activator: " + activatorModel.getID() + " returned false, will not restart");
        } else {
            error("Activator: " + activatorModel.getID() + " returned not true");
            if (crashCounter.get(activatorModel).get() < 100) {
                error("Until now activator: " + activatorModel.getID() + " was restarted: " + crashCounter.get(activatorModel).get() + " times, attempting restart.");
                crashCounter.get(activatorModel).incrementAndGet();
                submitActivator(activatorModel);
            } else {
                error("Activator: " + activatorModel.getID() + " reached restarting limit with " + crashCounter.get(activatorModel).get() + " restarts.");
            }
        }
    });
    CompletableFuture existing = futures.put(activatorModel, future);
    if (!existing.isDone())
        existing.cancel(true);
}

[Buggy Hunk]
if (!existing.isDone()) existing.cancel(true);

[Patch]
if (existing != null && !existing.isDone()) existing.cancel(true);

[Demonstration 3]

[Buggy Method]
@Override
public void onBindViewHolder(ListViewHolder holder, int position) {
    final Group currentGroup = items.get(position);
    Picasso.with(holder.list_img.getContext()).load(currentGroup.photo_50).transform(new CircleTransform()).into(holder.list_img);
    holder.list_txt.setText(currentGroup.name);
    holder.wrapper.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), ItemActivity.class);
            intent.putExtra("ID", -((long) currentGroup.id));
            intent.putExtra("TITLE", currentGroup.name);
            v.getContext().startActivity(intent);
        }
    });
}

[Buggy Hunk]
v.getContext().startActivity(intent);

[Patch]
((Activity) v.getContext()).startActivityForResult(intent,1);