<commit_before>package com.github.rongi.async;

import android.os.Handler;

import java.lang.ref.WeakReference;
import java.util.concurrent.Callable;

class Task<T> implements Runnable {

	public Task(Callable<T> callable, Callback callback, boolean callbackStrongReferenced) {
		this.callable = callable;
		if(callbackStrongReferenced) {
			callbackStrongReference = callback;
		} else if(callback != null && !callbackStrongReferenced) {
			this.callbackWeakReference = new WeakReference<Callback>(callback);
		}
	}

	public void abandon() {
		this.abandoned = true;
	}

	@Override
	public void run() {
		try{
			result = callable.call();
		} catch(Throwable e) {
			exception = e;
		}

		if(!abandoned) {
			final boolean success = handler.sendEmptyMessage(0);
			if(!success) {
				throw new IllegalStateException("Handler can't send message, probably sending not from GUI thread");
			}
		}
	}

	public Callable<T> getCallable() {
		return callable;
	}
	
	private Callback getCallback() {
		if(callbackStrongReference != null) {
			return callbackStrongReference;
		} else if(callbackWeakReference != null) {
			return callbackWeakReference.get();
		} else {
			return null;
		}
	}

	private final Handler handler = new Handler() {
		@SuppressWarnings("unchecked")
		public void handleMessage(android.os.Message msg) {
			final com.github.rongi.async.Callback callback = getCallback();
			if(callback != null && !abandoned) {
				callback.onFinish(result, callable, exception);
			}
		}
	};

	private final Callable<T> callable;
	
	private WeakReference<Callback> callbackWeakReference;
	private Callback callbackStrongReference;

	private boolean abandoned;

	private T result;
	private Throwable exception;

}
<commit_msg>nullify callback references on abandon<commit_after>package com.github.rongi.async;

import android.os.Handler;

import java.lang.ref.WeakReference;
import java.util.concurrent.Callable;

class Task<T> implements Runnable {

	public Task(Callable<T> callable, Callback callback, boolean callbackStrongReferenced) {
		this.callable = callable;
		if(callbackStrongReferenced) {
			callbackStrongReference = callback;
		} else if(callback != null && !callbackStrongReferenced) {
			this.callbackWeakReference = new WeakReference<Callback>(callback);
		}
	}

	public void abandon() {
		this.abandoned = true;
		callbackStrongReference = null;
		callbackWeakReference = null;
	}

	@Override
	public void run() {
		try{
			result = callable.call();
		} catch(Throwable e) {
			exception = e;
		}

		if(!abandoned) {
			final boolean success = handler.sendEmptyMessage(0);
			if(!success) {
				throw new IllegalStateException("Handler can't send message, probably sending not from GUI thread");
			}
		}
	}

	public Callable<T> getCallable() {
		return callable;
	}
	
	private Callback getCallback() {
		if(callbackStrongReference != null) {
			return callbackStrongReference;
		} else if(callbackWeakReference != null) {
			return callbackWeakReference.get();
		} else {
			return null;
		}
	}

	private final Handler handler = new Handler() {
		@SuppressWarnings("unchecked")
		public void handleMessage(android.os.Message msg) {
			final com.github.rongi.async.Callback callback = getCallback();
			if(callback != null && !abandoned) {
				callback.onFinish(result, callable, exception);
			}
		}
	};

	private final Callable<T> callable;
	
	private WeakReference<Callback> callbackWeakReference;
	private Callback callbackStrongReference;

	private boolean abandoned;

	private T result;
	private Throwable exception;

}

{'fraction_non_alphanumeric': 0.10431350436989005, 'fraction_numerical': 0.000563856780377784, 'mean_word_length': 4.450076804915515, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5097922', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1041, 'n_words': 258}