From c953e0b4319da0976ece877c09b648a55bc57d9f Mon Sep 17 00:00:00 2001 From: Mike Diarmid Date: Thu, 11 Apr 2019 03:11:24 -0700 Subject: [PATCH] JSStackTrace -> Ensure lineNumber exists before consuming (#24399) Summary: Fixes https://github.com/facebook/react-native/issues/24382 [ANDROID] [INTERNAL] - Fixed a `NoSuchKeyException` when parsing JS stack frames without line numbers. Pull Request resolved: https://github.com/facebook/react-native/pull/24399 Differential Revision: D14890746 Pulled By: cpojer fbshipit-source-id: cea3653076484ad624084c370439f8a39c303083 --- .../com/facebook/react/util/JSStackTrace.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/util/JSStackTrace.java b/ReactAndroid/src/main/java/com/facebook/react/util/JSStackTrace.java index a80101533e87b3..1a58a8f168433c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/util/JSStackTrace.java +++ b/ReactAndroid/src/main/java/com/facebook/react/util/JSStackTrace.java @@ -24,8 +24,18 @@ public static String format(String message, ReadableArray stack) { stringBuilder .append(frame.getString("methodName")) .append("@") - .append(parseFileId(frame)) - .append(frame.getInt("lineNumber")); + .append(parseFileId(frame)); + + if (frame.hasKey("lineNumber") && + !frame.isNull("lineNumber") && + frame.getType("lineNumber") == ReadableType.Number) { + stringBuilder + .append(frame.getInt("lineNumber")); + } else { + stringBuilder + .append(-1); + } + if (frame.hasKey("column") && !frame.isNull("column") && frame.getType("column") == ReadableType.Number) { @@ -33,6 +43,7 @@ public static String format(String message, ReadableArray stack) { .append(":") .append(frame.getInt("column")); } + stringBuilder.append("\n"); } return stringBuilder.toString();