From 7b638eefc861f7ae3187e4487117071826ec13bf Mon Sep 17 00:00:00 2001 From: vmutafov Date: Mon, 9 Sep 2019 14:46:18 +0300 Subject: [PATCH] Fix cyclic dependency in early-thrown NativeScriptException and throw error if missing metadata folder --- test-app/runtime/src/main/cpp/MetadataNode.cpp | 7 +++++++ test-app/runtime/src/main/cpp/NativeScriptException.cpp | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test-app/runtime/src/main/cpp/MetadataNode.cpp b/test-app/runtime/src/main/cpp/MetadataNode.cpp index eace37113..294892adf 100644 --- a/test-app/runtime/src/main/cpp/MetadataNode.cpp +++ b/test-app/runtime/src/main/cpp/MetadataNode.cpp @@ -11,6 +11,7 @@ #include "Runtime.h" #include #include +#include #include "ManualInstrumentation.h" #include "v8.h" @@ -1698,6 +1699,12 @@ void MetadataNode::BuildMetadata(const string& filesPath) { string baseDir = filesPath; baseDir.append("/metadata"); + + DIR* dir = opendir(baseDir.c_str()); + if(dir == nullptr){ + throw NativeScriptException(string("metadata folder couldn't be opened!")); + } + string nodesFile = baseDir + "/treeNodeStream.dat"; string namesFile = baseDir + "/treeStringsStream.dat"; string valuesFile = baseDir + "/treeValueStream.dat"; diff --git a/test-app/runtime/src/main/cpp/NativeScriptException.cpp b/test-app/runtime/src/main/cpp/NativeScriptException.cpp index 3975e357a..1ce34b407 100644 --- a/test-app/runtime/src/main/cpp/NativeScriptException.cpp +++ b/test-app/runtime/src/main/cpp/NativeScriptException.cpp @@ -71,9 +71,10 @@ void NativeScriptException::ReThrowToJava() { JEnv env; auto isolate = Isolate::GetCurrent(); - auto objectManager = Runtime::GetObjectManager(isolate); + if (!m_javaException.IsNull()) { + auto objectManager = Runtime::GetObjectManager(isolate); auto excClassName = objectManager->GetClassName((jobject) m_javaException); if (excClassName == "com/tns/NativeScriptException") { ex = m_javaException; @@ -101,6 +102,7 @@ void NativeScriptException::ReThrowToJava() { if (ex == nullptr) { ex = static_cast(env.NewObject(NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_JSVALUE_CTOR_ID, (jstring) msg, (jstring)stackTrace, reinterpret_cast(m_javascriptException))); } else { + auto objectManager = Runtime::GetObjectManager(isolate); auto excClassName = objectManager->GetClassName(ex); if (excClassName != "com/tns/NativeScriptException") { ex = static_cast(env.NewObject(NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_THROWABLE_CTOR_ID, (jstring) msg, (jstring)stackTrace, ex));