From 85d208632164e5c4491ea716a79423fb8a456259 Mon Sep 17 00:00:00 2001 From: Sakari Tuominen Date: Thu, 12 May 2016 01:44:43 -0700 Subject: [PATCH] Fix a bug, if clipData is null we can not ask getItemCount() from it Summary: I ran into problems when using Clipboard.getString() in Android. The method seems to work fine when there is *something* in the clipboard, but when it's empty the app crashes. I think I've tracked down the bug to ClipboardModule.java@58. When clipData is null, the promise is resolved with an empty string. However, after that the rest of the block is executed. There should be a return or an 'else if' like in my pr. Screenshot of the error message when clipboard is empty: ![image](https://cloud.githubusercontent.com/assets/7509183/15206922/44bd2094-182b-11e6-9400-6a59c513de24.png) Closes https://github.com/facebook/react-native/pull/7527 Differential Revision: D3292232 fbshipit-source-id: d2191286c49ee31233203fab4648449964b9d950 --- .../com/facebook/react/modules/clipboard/ClipboardModule.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/clipboard/ClipboardModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/clipboard/ClipboardModule.java index 0ea6c9052..a51f93e7c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/clipboard/ClipboardModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/clipboard/ClipboardModule.java @@ -54,8 +54,7 @@ public class ClipboardModule extends ReactContextBaseJavaModule { ClipData clipData = clipboard.getPrimaryClip(); if (clipData == null) { promise.resolve(""); - } - if (clipData.getItemCount() >= 1) { + } else if (clipData.getItemCount() >= 1) { ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0); promise.resolve("" + firstItem.getText()); } else {