Skip to content

Commit 9715517

Browse files
committed
fix(http-cache): clear the exception a failed ModuleHttpCache lookup leaves pending
JEnv::FindClass returns null with the lookup's exception pending. Reading the startup setting now clears it and keeps the default, and ClearModuleHttpCache throws it as a NativeScriptException instead of passing a null class on to GetStaticMethodID.
1 parent f00182f commit 9715517

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎test-app/runtime/src/main/cpp/HttpLoader.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,15 @@ static void InitializeModuleHttpCacheSetting() {
321321
JEnv env;
322322
jclass cls = env.FindClass("com/tns/ModuleHttpCache");
323323
if (cls == nullptr) {
324+
env.ExceptionClear();
324325
return;
325326
}
326327
jmethodID mid = env.GetStaticMethodID(cls, "isEnabledAtStartup", "()Z");
327-
if (mid != nullptr) {
328-
s_moduleHttpCacheSetting.store(env.CallStaticBooleanMethod(cls, mid) == JNI_TRUE);
328+
if (mid == nullptr) {
329+
env.ExceptionClear();
330+
return;
329331
}
332+
s_moduleHttpCacheSetting.store(env.CallStaticBooleanMethod(cls, mid) == JNI_TRUE);
330333
} catch (...) {
331334
// Enabled.
332335
}
@@ -351,6 +354,10 @@ void AddModuleHttpCacheInspectorDisable(int delta) {
351354
void ClearModuleHttpCache() {
352355
JEnv env;
353356
jclass cls = env.FindClass("com/tns/ModuleHttpCache");
357+
if (cls == nullptr) {
358+
// Takes the ClassNotFoundException FindClass left pending.
359+
throw NativeScriptException(env);
360+
}
354361
jmethodID mid = env.GetStaticMethodID(cls, "clear", "()V");
355362
env.CallStaticVoidMethod(cls, mid);
356363
}

0 commit comments

Comments
 (0)