Skip to content

Commit

Permalink
fix nullpointer, make blacklist threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed Nov 11, 2017
1 parent 80b73e3 commit d50a452
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.File;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class ThumbnailLoader {
// This gets cleared by the Garbage Collector everytime we get low on memory.
private ConcurrentHashMap<String, SoftReference<Bitmap>> mSoftBitmapCache;
private LinkedHashMap<String, Bitmap> mHardBitmapCache;
private ArrayList<String> mBlacklist;
private List<String> mBlacklist;

/**
* Used for loading and decoding thumbnails from files.
Expand All @@ -82,7 +83,7 @@ public void run() {
purgeHandler = new Handler();
mExecutor = new PausableThreadPoolExecutor(POOL_SIZE);

mBlacklist = new ArrayList<>();
mBlacklist = Collections.synchronizedList(new ArrayList<String>());
mSoftBitmapCache = new ConcurrentHashMap<>(MAX_CACHE_CAPACITY / 2);
mHardBitmapCache = new LinkedHashMap<String, Bitmap>(MAX_CACHE_CAPACITY / 2, 0.75f, true) {

Expand Down Expand Up @@ -166,8 +167,6 @@ public void stopPurgeTimer() {

/**
* Purges the cache every (DELAY_BEFORE_PURGE) milliseconds.
*
* @see DELAY_BEFORE_PURGE
*/
private void resetPurgeTimer() {
purgeHandler.removeCallbacks(purger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ private boolean copyFile(File oldFile, File newFile) {
// ignore
}
try {
output.close();
if (output != null) {
output.close();
}
} catch (IOException e) {
// ignore
}
Expand Down

0 comments on commit d50a452

Please sign in to comment.