Commit 4e223620 authored by Tobias Sargeant's avatar Tobias Sargeant Committed by Commit Bot

[supportlib] getOrCreatePeer shouldn't throw a checked exception.

We are restricted to use functor-like objects that are part of the root
classloader. This means that changing from Callable is not practical.
However the fact that Callable#call can throw a checked exception is
inconvenient for code that uses getOrCreatePeer, especially as it is not
expected that the peer creation callable will ever actually throw.

For this reason, it's best if getOrCreatePeer rethrows the checked
exception wrapped in an unchecked RuntimeException.

Bug: 908269
Change-Id: I726d1cc75f13cafa9f62169069a237cc9e129b4d
Reviewed-on: https://chromium-review.googlesource.com/c/1349974Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Commit-Queue: Tobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610953}
parent 0fdb4980
......@@ -35,5 +35,5 @@ public interface IsomorphicObjectBoundaryInterface {
* @return The peer object associated with this object, which either exists already, or has
* been freshly created and recorded.
*/
Object getOrCreatePeer(Callable<Object> creationCallable) throws Exception;
Object getOrCreatePeer(Callable<Object> creationCallable);
}
......@@ -16,14 +16,18 @@ abstract class IsomorphicAdapter implements IsomorphicObjectBoundaryInterface {
abstract AwSupportLibIsomorphic getPeeredObject();
@Override
public Object getOrCreatePeer(Callable<Object> creationCallable) throws Exception {
public Object getOrCreatePeer(Callable<Object> creationCallable) {
AwSupportLibIsomorphic peeredObject = getPeeredObject();
if (peeredObject == null) {
return null;
}
Object peer = peeredObject.getSupportLibObject();
if (peer == null) {
peeredObject.setSupportLibObject(peer = creationCallable.call());
try {
peeredObject.setSupportLibObject(peer = creationCallable.call());
} catch (Exception e) {
throw new RuntimeException("Could not create peered object", e);
}
}
return peer;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment