<commit_before>package de.marcusschiesser.gallerista.tasks;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.URL;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import de.marcusschiesser.gallerista.utils.BitmapCacheUtils;

public class BitmapWorkerTask extends AsyncTask<URL, Void, Bitmap> {

	private final WeakReference<ImageView> imageViewReference;
	private URL url;

	private BitmapWorkerTask(ImageView imageView) {
		// Use a WeakReference to ensure the ImageView can be garbage collected
		imageViewReference = new WeakReference<ImageView>(imageView);
	}

	// Decode image in background.
	@Override
	protected Bitmap doInBackground(URL... param) {
		url = param[0];
		try {
			final Bitmap bitmap = BitmapFactory.decodeStream(url
					.openConnection().getInputStream());
			BitmapCacheUtils.addBitmapToMemoryCache(url, bitmap);
			return bitmap;
		} catch (IOException e) {
			Log.e(BitmapWorkerTask.class.getName(), "error cannot load bitmap");
			return null;
		}
	}

	// Once complete, see if ImageView is still around and set bitmap.
	@Override
	protected void onPostExecute(Bitmap bitmap) {
		if (isCancelled()) {
			bitmap = null;
		}

		if (imageViewReference != null && bitmap != null) {<commit_msg>fixed NPE if bitmap could not be decoded<commit_after>package de.marcusschiesser.gallerista.tasks;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.URL;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import de.marcusschiesser.gallerista.utils.BitmapCacheUtils;

public class BitmapWorkerTask extends AsyncTask<URL, Void, Bitmap> {

	private final WeakReference<ImageView> imageViewReference;
	private URL url;

	private BitmapWorkerTask(ImageView imageView) {
		// Use a WeakReference to ensure the ImageView can be garbage collected
		imageViewReference = new WeakReference<ImageView>(imageView);
	}

	// Decode image in background.
	@Override
	protected Bitmap doInBackground(URL... param) {
		url = param[0];
		try {
			final Bitmap bitmap = BitmapFactory.decodeStream(url
					.openConnection().getInputStream());
			if(bitmap!=null) {
				BitmapCacheUtils.addBitmapToMemoryCache(url, bitmap);
			}
			return bitmap;
		} catch (IOException e) {
			Log.e(BitmapWorkerTask.class.getName(), "error cannot load bitmap");
			return null;
		}
	}

	// Once complete, see if ImageView is still around and set bitmap.
	@Override
	protected void onPostExecute(Bitmap bitmap) {
		if (isCancelled()) {
			bitmap = null;
		}

		if (imageViewReference != null && bitmap != null) {
{'fraction_non_alphanumeric': 0.09732516919110538, 'fraction_numerical': 0.0006445375443119562, 'mean_word_length': 4.992277992277992, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3752408', 'n_tokens_mistral': 965, 'n_tokens_neox': 879, 'n_words': 240}