Establish a global reference before saving a class into a global.

A local reference is obtained to the string class for the purpose of
using it later in another routine to create string object arrays.
However, the local reference is invalid by the time it is next used.
Making the string class reference a global reference eliminates the
problem.

Change-Id: I8a04642e0ed3060f2fff2cb63996559f004aacff
This commit is contained in:
Carl Shapiro
2011-03-03 14:22:28 -08:00
parent 84af86c4dd
commit c1318babb4

View File

@@ -1806,7 +1806,9 @@ int register_android_content_AssetManager(JNIEnv* env)
= env->GetFieldID(assetManager, "mObject", "I");
LOG_FATAL_IF(gAssetManagerOffsets.mObject == NULL, "Unable to find AssetManager.mObject");
g_stringClass = env->FindClass("java/lang/String");
jclass stringClass = env->FindClass("java/lang/String");
LOG_FATAL_IF(stringClass == NULL, "Unable to find class java/lang/String");
g_stringClass = (jclass)env->NewGlobalRef(stringClass);
return AndroidRuntime::registerNativeMethods(env,
"android/content/res/AssetManager", gAssetManagerMethods, NELEM(gAssetManagerMethods));