Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
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,7 +228,7 @@ public String getIdStringFromIdFieldRef(JFieldRef idRef) {
throw new IllegalStateException("Unable to extract target name from JFieldRef");
}

public JTryBlock surroundWithTryCatch(EBeanHolder holder, JBlock block, JBlock content, String exceptionMessage) {
public JTryBlock surroundWithTryCatch(EBeanHolder holder, JBlock block, JBlock content, String exceptionMessage, boolean propagate) {
Classes classes = holder.classes();
JTryBlock tryBlock = block._try();
tryBlock.body().add(content);
Expand All @@ -239,6 +239,9 @@ public JTryBlock surroundWithTryCatch(EBeanHolder holder, JBlock block, JBlock c
errorInvoke.arg(exceptionMessage);
errorInvoke.arg(exceptionParam);
catchBlock.body().add(errorInvoke);
if (propagate) {
catchBlock.body()._throw(exceptionParam);
}
return tryBlock;
}

Expand All @@ -257,7 +260,7 @@ public JDefinedClass createDelegatingAnonymousRunnableClass(EBeanHolder holder,

JBlock runMethodBody = runMethod.body();

surroundWithTryCatch(holder, runMethodBody, previousMethodBody, "A runtime exception was thrown while executing code in a runnable");
surroundWithTryCatch(holder, runMethodBody, previousMethodBody, "A runtime exception was thrown while executing code in a runnable", true);

return anonymousRunnableClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t
executeMethod.annotate(Override.class);

JBlock runMethodBody = executeMethod.body();
helper.surroundWithTryCatch(holder, runMethodBody, previousMethodBody, "A runtime exception was thrown while executing code in a background task");
helper.surroundWithTryCatch(holder, runMethodBody, previousMethodBody, "A runtime exception was thrown while executing code in a background task", true);

Background annotation = element.getAnnotation(Background.class);
String id = annotation.id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,26 @@ public void cancellableSerializedBackgroundTasks() {
}
}

@Test
public void propagateException() {
BackgroundExecutor.setExecutor(new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
});
try {
activity.backgroundThrowException();
Assert.fail("Exception should be propagated in @Background annotated methods");
} catch (RuntimeException e) {
// good
}
try {
activity.uiThreadThrowException();
Assert.fail("Exception should be propagated in @UIThread annotated methods");
} catch (RuntimeException e) {
// good
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,14 @@ void backgrounddUsingArrayParamtersMethod(MySerializableBean[] array) {
@Background
void backgroundUsingArrayParamtersMethod(MySerializableBean[][] array) {
}

@Background
void backgroundThrowException() {
throw new RuntimeException();
}

@UiThread
void uiThreadThrowException() {
throw new RuntimeException();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.