Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: jni/Utils.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Stupid auto-formatter^^ Created Feb. 4, 2015, 12:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jni/Utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/Utils.cpp
diff --git a/jni/Utils.cpp b/jni/Utils.cpp
index ad01d20b04d7bde4650580116f37036d1fa93254..ad7b5054de7acf72316126c83bcebb24171be229 100644
--- a/jni/Utils.cpp
+++ b/jni/Utils.cpp
@@ -35,21 +35,23 @@ std::string JniJavaToStdString(JNIEnv* env, jstring str)
jobject NewJniArrayList(JNIEnv* env)
{
- jclass clazz = env->FindClass("java/util/ArrayList");
- jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V");
- return env->NewObject(clazz, ctor);
+ JniLocalReference<jclass> clazz(env, env->FindClass("java/util/ArrayList"));
+ jmethodID ctor = env->GetMethodID(*clazz, "<init>", "()V");
+ return env->NewObject(*clazz, ctor);
}
void JniAddObjectToList(JNIEnv* env, jobject list, jobject value)
{
- jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lang/Object;)Z");
+ JniLocalReference<jclass> clazz(env, env->GetObjectClass(list));
+ jmethodID add = env->GetMethodID(*clazz, "add", "(Ljava/lang/Object;)Z");
env->CallBooleanMethod(list, add, value);
}
void JniThrowException(JNIEnv* env, const std::string& message)
{
- jclass clazz = env->FindClass(PKG("AdblockPlusException"));
- env->ThrowNew(clazz, message.c_str());
+ JniLocalReference<jclass> clazz(env,
+ env->FindClass(PKG("AdblockPlusException")));
+ env->ThrowNew(*clazz, message.c_str());
}
void JniThrowException(JNIEnv* env, const std::exception& e)
« no previous file with comments | « jni/Utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld