Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch OutOfMemoryError in decode for v3 #1057

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,15 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {

verify(resource).recycle();
}

@Test
public void testNotifiesManagerOfFailureIfJobThrowsOOMDecodingFromSource() throws Exception {
runnable.run();

OutOfMemoryError expected = new OutOfMemoryError("test");
when(job.decodeFromSource()).thenThrow(expected);
runnable.run();

verify(manager).onException(any(ErrorWrappingGlideException.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bumptech.glide.load.engine;

import static org.junit.Assert.assertSame;

import org.junit.Test;

public class ErrorWrappingGlideExceptionTest {

@Test(expected = NullPointerException.class)
public void testNullErrorCauseThrowsException() throws Exception {
throw new ErrorWrappingGlideException(null);
}

@Test
public void testGetCauseReturnsSameError() throws Exception {
Error cause = new OutOfMemoryError("Test");
ErrorWrappingGlideException exception = new ErrorWrappingGlideException(cause);
assertSame("Cause should be our error", cause, exception.getCause());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void run() {
Resource<?> resource = null;
try {
resource = decode();
} catch (OutOfMemoryError e) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Out Of Memory Error decoding", e);
}
exception = new ErrorWrappingGlideException(e);
} catch (Exception e) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Exception decoding", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bumptech.glide.load.engine;

/**
* An exception class used for wrapping and distinguishing errors such as {@link OutOfMemoryError}.
*/
public class ErrorWrappingGlideException extends Exception {
public ErrorWrappingGlideException(Error error) {
super(error);
if (error == null) {
throw new NullPointerException("The causing error must not be null");
}
}

@Override
public Error getCause() {
// cast is safe because constructor ensures there must be a cause, and it must be an Error
return (Error) super.getCause();
}
}