Opened 11 years ago

Closed 11 years ago

#352 closed defect (fixed)

JSS fails to introspect foo(long) methods

Reported by: Mark Evenson Owned by:
Priority: major Milestone: 1.3.1
Component: JSS Version: 1.4.0-dev
Keywords: has-test Cc:
Parent Tickets:

Description

package com.test;

public class Test {
  public void test (long argument) {
    System.out.println ("argument = " + argument);
  }
}

$ java -cp ".;abcl/dist/abcl.jar" org.armedbear.lisp.Main
Armed Bear Common Lisp 1.4.0-dev-svn-14662
Java 1.7.0_51 Oracle Corporation
Java HotSpot(TM) 64-Bit Server VM
Low-level initialization completed in 0.35 seconds.
Startup completed in 4.222 seconds.
Type ":help" for a list of available commands.

CL-USER(1): (jnew "com.test.Test")
#<com.test.Test com.test.Test@1c040a30 {4D38E3AE}>

CL-USER(14): (jcall (jmethod "com.test.Test" "test" "long") (jnew "com.test.Test") 1)
argument = 1
NIL

CL-USER(3): (require 'abcl-contrib)
Using probed value of abcl-contrib:
'C:/workspace/abcl/dist/abcl-contrib.jar'.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/quicklisp/ to ASDF.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/mvn/ to ASDF.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/jss/ to ASDF.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/jfli/ to ASDF.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/asdf-jar/ to ASDF.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/asdf-install/ to ASDF.
Added jar:file:C:/workspace/abcl/dist/abcl-contrib.jar!/abcl-asdf/ to ASDF.
("asdf" "ASDF" "ABCL-CONTRIB")

CL-USER(4): (require 'jss)
("LOOP" "COMPILER-TYPES" "KNOWN-FUNCTIONS" "JVM-CLASS-FILE" "KNOWN-SYMBOLS" "DUMP-FORM" "COMPILER-ERROR" "JVM-INSTRUCTIONS" "JVM" "COMPILER-PASS1" "COMPILER-PASS2" "JSS")

CL-USER(5): (#"test" (jnew "com.test.Test") 1)
#<THREAD "interpreter" {481153E5}>: Debugger invoked on condition of type JAVA-EXCEPTION
  Java exception 'java.lang.NoSuchMethodException: No applicable method named test found in com.test.Test'.
Restarts:
  0: TOP-LEVEL Return to top level.
[1] CL-USER(6): 0

Attachments (2)

is-assignable.patch (3.2 KB) - added by Mark Evenson 11 years ago.
Olof's further patch
DummyMethods.java (917 bytes) - added by Mark Evenson 11 years ago.
Olof's test Java code

Download all attachments as: .zip

Change History (5)

comment:1 Changed 11 years ago by Mark Evenson

Component: (A)MOPJSS

comment:2 Changed 11 years ago by Mark Evenson

On #abcl ferada suggests the following would work:

Index: src/org/armedbear/lisp/Java.java
===================================================================
--- src/org/armedbear/lisp/Java.java    (revision 14662)
+++ src/org/armedbear/lisp/Java.java    (working copy)
@@ -1040,14 +1040,37 @@
         return result;
     }

+    private static boolean isAssignable(Class<?> from, Class<?> to) {
+        if (from.isPrimitive()) {
+            from = getBoxedClass(from);
+        }
+        if (to.isPrimitive()) {
+            to = getBoxedClass(to);
+        }
+        if (to.isAssignableFrom(from)) {
+            return true;
+        }
+        if (Byte.class.equals(from)) {
+            return Short.class.equals(to) || Integer.class.equals(to) || Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
+        } else if (Short.class.equals(from) || Character.class.equals(from)) {
+            return Integer.class.equals(to) || Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
+        } else if (Integer.class.equals(from)) {
+            return Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
+        } else if (Long.class.equals(from)) {
+            return Float.class.equals(to) || Double.class.equals(to);
+        } else if (Float.class.equals(from)) {
+            return Double.class.equals(to);
+        }
+        return false;
+    }
+
     private static boolean isApplicableMethod(Class<?>[] methodTypes,
             Object[] args) {
         for (int i = 0; i < methodTypes.length; ++i) {
             Class<?> methodType = methodTypes[i];
             Object arg = args[i];
             if (methodType.isPrimitive()) {
-                Class<?> x = getBoxedClass(methodType);
-                if (!x.isInstance(arg)) {
+                if (!isAssignable(arg.getClass(), methodType)) {
                     return false;
                 }
             } else if (arg != null && !methodType.isInstance(arg)) {

aka a reimplementation of org.apache.commons.lang.ClassUtils?.isAssignable instead of the standard isAssignableFrom test

Changed 11 years ago by Mark Evenson

Attachment: is-assignable.patch added

Olof's further patch

Changed 11 years ago by Mark Evenson

Attachment: DummyMethods.java added

Olof's test Java code

comment:3 Changed 11 years ago by Mark Evenson

Milestone: 1.4.01.3.1
Resolution: fixed
Status: newclosed

http://abcl.org/trac/changeset/14682 #14682 seems to have fixed things.

Note: See TracTickets for help on using tickets.