From e64618374b2e23ddd0ec91b777c2677c19ac5de3 Mon Sep 17 00:00:00 2001 From: Theo Yaung Date: Wed, 21 Dec 2016 10:52:26 -0800 Subject: [PATCH] Fail-Fast on Redundant Java Callback Invocations Reviewed By: dcaspi Differential Revision: D4354731 fbshipit-source-id: d23351f23c8c5962da60af77340166fcb1314d78 --- .../main/java/com/facebook/react/bridge/CallbackImpl.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/CallbackImpl.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/CallbackImpl.java index a7bc85802..7ba988a95 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/CallbackImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/CallbackImpl.java @@ -17,15 +17,23 @@ public final class CallbackImpl implements Callback { private final CatalystInstance mCatalystInstance; private final ExecutorToken mExecutorToken; private final int mCallbackId; + private boolean mInvoked; public CallbackImpl(CatalystInstance bridge, ExecutorToken executorToken, int callbackId) { mCatalystInstance = bridge; mExecutorToken = executorToken; mCallbackId = callbackId; + mInvoked = false; } @Override public void invoke(Object... args) { + if (mInvoked) { + throw new RuntimeException("Illegal callback invocation from native "+ + "module. This callback type only permits a single invocation from "+ + "native code."); + } mCatalystInstance.invokeCallback(mExecutorToken, mCallbackId, Arguments.fromJavaArgs(args)); + mInvoked = true; } }