From d7bd6cce38d42dbced48fc8abed96472126e5d69 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 a80101533..1a58a8f16 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 class JSStackTrace { 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 class JSStackTrace { .append(":") .append(frame.getInt("column")); } + stringBuilder.append("\n"); } return stringBuilder.toString();