Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: base/android/jni_android.cc

Issue 1008363004: Fix invalid class names passed to ClassLoader.loadClass. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/jni_android.cc
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc
index a2de00aca2a3fcf2ce0c8c82bd06afc48229c256..1b715dc7d544955ed5bc316d8808b6f35cd141fe 100644
--- a/base/android/jni_android.cc
+++ b/base/android/jni_android.cc
@@ -159,10 +159,25 @@ const jobject GetApplicationContext() {
ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* class_name) {
jclass clazz;
if (!g_class_loader.Get().is_null()) {
+ // ClassLoader.loadClass expects a classname with components separated by
+ // dots instead of the slashes that JNIEnv::FindClass expects. The JNI
+ // generator generates names with slashes, so we have to replace them here.
+ // TODO(torne): move to an approach where we always use ClassLoader except
+ // for the special case of base::android::GetClassLoader(), and change the
+ // JNI generator to generate dot-separated names. http://crbug.com/461773
+ size_t bufsize = strlen(class_name) + 1;
+ char dotted_name[bufsize];
+ memmove(dotted_name, class_name, bufsize);
+ for (size_t i = 0; i < bufsize; ++i) {
+ if (dotted_name[i] == '/') {
+ dotted_name[i] = '.';
+ }
+ }
+
clazz = static_cast<jclass>(
env->CallObjectMethod(g_class_loader.Get().obj(),
g_class_loader_load_class_method_id,
- ConvertUTF8ToJavaString(env, class_name).obj()));
+ ConvertUTF8ToJavaString(env, dotted_name).obj()));
} else {
clazz = env->FindClass(class_name);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698