Permalink
Browse files

fixed bad classloader issue

  • Loading branch information...
joeferner committed May 31, 2012
1 parent f701f4f commit 6ed9fe7d3560e66fa2b7a72e4c3163faa7d1ceea
Showing with 15 additions and 3 deletions.
  1. +1 −1 src/javaObject.cpp
  2. +7 −1 src/utils.cpp
  3. +6 −0 test/dynamicProxy-test.js
  4. +1 −1 test/javaObject-test.js
View
@@ -99,7 +99,7 @@ JavaObject::~JavaObject() {
InstanceMethodCallBaton* baton = new InstanceMethodCallBaton(self->m_java, self, method, methodArgs, callback);
baton->run();
- END_CALLBACK_FUNCTION("\"Method '" << *methodName << "' called without a callback did you mean to use the Sync version?\"");
+ END_CALLBACK_FUNCTION("\"Method '" << methodNameStr << "' called without a callback did you mean to use the Sync version?\"");
}
/*static*/ v8::Handle<v8::Value> JavaObject::methodCallSync(const v8::Arguments& args) {
View
@@ -220,11 +220,17 @@ jobject v8ToJava(JNIEnv* env, v8::Local<v8::Value> arg) {
jmethodID class_getClassLoader = env->GetMethodID(classClazz, "getClassLoader", "()Ljava/lang/ClassLoader;");
jobject classLoader = env->CallObjectMethod(dynamicInterface, class_getClassLoader);
+ if(classLoader == NULL) {
+ jclass objectClazz = env->FindClass("java/lang/Object");
+ jmethodID object_getClass = env->GetMethodID(classClazz, "getClass", "()Ljava/lang/Class;");
+ jobject jobjClass = env->CallObjectMethod(jobj, object_getClass);
+ classLoader = env->CallObjectMethod(jobjClass, class_getClassLoader);
+ }
jclass proxyClass = env->FindClass("java/lang/reflect/Proxy");
jmethodID proxy_newProxyInstance = env->GetStaticMethodID(proxyClass, "newProxyInstance", "(Ljava/lang/ClassLoader;[Ljava/lang/Class;Ljava/lang/reflect/InvocationHandler;)Ljava/lang/Object;");
if(classLoader == NULL) {
- printf("Could not create classloader for Proxy\n");
+ printf("Could not get classloader for Proxy\n");
return NULL;
}
if(classArray == NULL) {
@@ -66,10 +66,16 @@ exports['Dynamic Proxy'] = nodeunit.testCase({
var thread = java.newInstanceSync("java.lang.Thread", myProxy);
thread.startSync();
+ var timeout = 50;
+
function waitForThread() {
if (callCount === 1) {
return test.done();
}
+ timeout--;
+ if (timeout < 0) {
+ test.done(new Error("Timeout"));
+ }
setTimeout(waitForThread, 100);
}
View
@@ -15,5 +15,5 @@ exports['Java Object'] = nodeunit.testCase({
this.testObj.nonstaticInt = 112;
test.equal(this.testObj.nonstaticInt, 112);
test.done();
- },
+ }
});

0 comments on commit 6ed9fe7

Please sign in to comment.