Fixes #229 so that JCALL works with static member classes.

Added non-working test to putative JSS test suite.
parent bc1c43bd
;;;; -*- Mode: LISP -*- ;;;; -*- Mode: LISP -*-
(asdf:defsystem :jss (asdf:defsystem :jss
:author "Alan Ruttenberg, Mark Evenson" :author "Alan Ruttenberg, Mark Evenson"
:version "3.0.4" :version "3.0.5"
:components :components ((:module base
((:module base
:pathname "" :serial t :pathname "" :serial t
:components ((:file "packages") :components ((:file "packages")
(:file "invoke") (:file "invoke")
(:file "classpath") (:file "classpath")
(:file "compat"))))) (:file "compat")))))
#+nil FIXME
(asdf:defsystem :jss-tests
:depends-on (jss abcl abcl-test-lisp)
:components ((:module tests
:pathname ""
:components ((:file "tests")))))
......
...@@ -12,4 +12,16 @@ ...@@ -12,4 +12,16 @@
(substring "01234" 2))) (substring "01234" 2)))
"234") "234")
;;; http://trac.common-lisp.net/armedbear/ticket/229
(deftest jss.jcall.1
(let* ((headers (#"getHeaderFields"
(#"openConnection"
(jss::new 'java.net.url "http://google.com"))))
(second-header (#"get" *headers*
(second (jss::set-to-list (#"keySet"
*headers*))))))
(#"size" *ural*))
-1)
...@@ -888,6 +888,12 @@ public final class Java ...@@ -888,6 +888,12 @@ public final class Java
else else
methodArgs[i-2] = arg.javaInstance(argTypes[i-2]); methodArgs[i-2] = arg.javaInstance(argTypes[i-2]);
} }
if (!method.isAccessible()) {
// Possible for static member classes: see #229
if (Modifier.isPublic(method.getModifiers())) {
method.setAccessible(true);
}
}
return JavaObject.getInstance(method.invoke(instance, methodArgs), return JavaObject.getInstance(method.invoke(instance, methodArgs),
translate, translate,
method.getReturnType()); method.getReturnType());
...@@ -961,14 +967,28 @@ public final class Java ...@@ -961,14 +967,28 @@ public final class Java
Class actualClass = null; Class actualClass = null;
if(method == null) { if(method == null) {
actualClass = instance.getClass(); actualClass = instance.getClass();
if(intendedClass != actualClass && if(intendedClass != actualClass) {
Modifier.isPublic(actualClass.getModifiers())) {
method = findMethod(actualClass, methodName, methodArgs); method = findMethod(actualClass, methodName, methodArgs);
if (method != null) {
if (isMethodCallableOnInstance(actualClass, method)) {
return method;
}
}
} }
} }
return method; return method;
} }
private static boolean isMethodCallableOnInstance(Class instance, Method method) {
if (Modifier.isPublic(method.getModifiers())) {
return true;
}
if (instance.isMemberClass()) {
return isMethodCallableOnInstance(instance.getEnclosingClass(), method);
}
return false;
}
private static Method findMethod(Class<?> c, String methodName, Object[] javaArgs) { private static Method findMethod(Class<?> c, String methodName, Object[] javaArgs) {
Method[] methods = c.getMethods(); Method[] methods = c.getMethods();
return findMethod(methods, methodName, javaArgs); return findMethod(methods, methodName, javaArgs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment