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

Added non-working test to putative JSS test suite.
parent bc1c43bd
;;;; -*- Mode: LISP -*-
(asdf:defsystem :jss
:author "Alan Ruttenberg, Mark Evenson"
:version "3.0.4"
:components
((:module base
:version "3.0.5"
:components ((:module base
:pathname "" :serial t
:components ((:file "packages")
(:file "invoke")
(:file "classpath")
(: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 @@
(substring "01234" 2)))
"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
else
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),
translate,
method.getReturnType());
......@@ -961,14 +967,28 @@ public final class Java
Class actualClass = null;
if(method == null) {
actualClass = instance.getClass();
if(intendedClass != actualClass &&
Modifier.isPublic(actualClass.getModifiers())) {
if(intendedClass != actualClass) {
method = findMethod(actualClass, methodName, methodArgs);
if (method != null) {
if (isMethodCallableOnInstance(actualClass, 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) {
Method[] methods = c.getMethods();
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