java plugin: Replace dots ('.') with slashes ('/') when loading a class.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 28 May 2009 10:10:42 +0000 (12:10 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 28 May 2009 10:10:42 +0000 (12:10 +0200)
Thanks to Randy Rizun for pointing this out:

Hi!

just wanted to point out an issue in cjni_config_load_plugin

the call to FindClass passes the "Name" verbatim from the LoadPlugin directive

one might intuitively say LoadPlugin "com.foobar.Plugin"

whereas FindClass wants to see it as "com/foobar/Plugin"

so I guess either (a) document LoadPlugin to say to use slashes or (b)
subst / for . in cjni_config_load_plugin or (c) something else?!?

of course, everything works fine if my plugin is in the 'default' java
package (i.e., no package name) =)

either way, thanks a lot for the great work!!

-Randy

src/java.c

index c12cdfc..6a98d82 100644 (file)
@@ -2179,6 +2179,15 @@ static int cjni_config_load_plugin (oconfig_item_t *ci) /* {{{ */
   class->class = NULL;
   class->object = NULL;
 
+  { /* Replace all dots ('.') with slashes ('/'). Dots are usually used
+       thorough the Java community, but (Sun's) `FindClass' and friends need
+       slashes. */
+    size_t i;
+    for (i = 0; class->name[i] != 0; i++)
+      if (class->name[i] == '.')
+        class->name[i] = '/';
+  }
+
   DEBUG ("java plugin: Loading class %s", class->name);
 
   class->class = (*jvm_env)->FindClass (jvm_env, class->name);