Skip to content

Commit

Permalink
Merge pull request #65 from livefront/fix-cancellation-exception
Browse files Browse the repository at this point in the history
Catch CancellationException that may result from cancelling the Future in clear / clearAll
  • Loading branch information
brian-livefront committed Mar 2, 2021
2 parents 6cceded + 3b35f2d commit ec114bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public void constructor() {
assertNull(fileDiskHandler3.getBytes(key));
}

@Test
public void getBytes_afterCancelling() {
// Should not trigger a CancellationException
mFileDiskHandler.clearAll();
mFileDiskHandler.getBytes("test");
}

@Test
public void getBytes_dataPresent() {
// Should return the previously stored data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -228,7 +229,10 @@ private void waitForFilesToLoad() {
}
try {
mPendingLoadFuture.get(BACKGROUND_WAIT_TIMEOUT_MS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
} catch (CancellationException |
InterruptedException |
ExecutionException |
TimeoutException e) {
// We've made a best effort to load the data in the background. We can simply proceed
// here.
}
Expand Down

0 comments on commit ec114bb

Please sign in to comment.