java/Class: use Java::LocalObject

This eliminates all but one DeleteLocalRef() call.
This commit is contained in:
Max Kellermann 2021-07-23 18:00:33 +02:00 committed by Max Kellermann
parent 31f7fede30
commit c9a9248c9f

View File

@ -58,23 +58,21 @@ public:
assert(env != nullptr);
assert(name != nullptr);
jclass cls = env->FindClass(name);
const Java::Class cls{env, env->FindClass(name)};
assert(cls != nullptr);
Set(env, cls);
env->DeleteLocalRef(cls);
}
bool FindOptional(JNIEnv *env, const char *name) noexcept {
assert(env != nullptr);
assert(name != nullptr);
jclass cls = env->FindClass(name);
const Java::Class cls{env, env->FindClass(name)};
if (DiscardException(env))
return false;
Set(env, cls);
env->DeleteLocalRef(cls);
return true;
}
};