Opened 9 years ago

Last modified 16 months ago

#259 closed defect

JAVA:JSTATIC cannot always be invoked properly — at Version 5

Reported by: Christoph Egger Owned by: Mark Evenson
Priority: critical Milestone: 1.6.1
Component: java Version: 1.1.0-dev
Keywords: java-interop needs-audit has-test Cc: siccegge@…
Parent Tickets:

Description (last modified by Mark Evenson)

The following doesn't work

(jstatic "asList" "java.util.Arrays" (java:jnew-array (jclass "int") 1))

Change History (5)

comment:1 Changed 9 years ago by Christoph Egger

Simplest test-case:

(jss:jarray-to-list (java:jnew-array (jclass "int") 40))

comment:2 Changed 9 years ago by Mark Evenson

Milestone: 1.1.0
Status: newaccepted
Version: 1.1.0-dev

Maybe something screwed up in our type mapping for JAVA-OBJECT. (java:jnew-array (jclass "int") 40) creates a JAVA-OBJECT whose intendedType is int[]. The code in java.isApplicableMethod() signals that java.lang.Arrays.asList(Object[]) is not an applicable method although the following code outputs "true" indicating that it should be matched, as it is successfully applicable.

     int i[] = {new Integer(40)};
     Object[] type = {1};
     Class clazz = type.getClass();

I tried fixing Java.isApplicableMethod() but it didn't work out in the time I had.

I have a simpler fix for JSS:JARRAY-TO-LIST which doesn't involve resolving this problem which I will commit shortly, but am noting the possibly deeper problem for followup.

comment:3 Changed 9 years ago by Mark Evenson

(In [14226]) Re #259: fix JSS:JLIST-TO-LIST.

This fixes the immediate problem, but leave the ticket open as far as
I can tell the following code fails in ABCL, but succeeds in the
equivalent Java code indicating we need to fix

(jstatic "asList" "java.util.Arrays" (java:jnew-array (jclass "int") 1))

comment:4 Changed 9 years ago by Mark Evenson

Description: modified (diff)
Summary: jss:jarray-to-list failsJAVA:JSTATIC cannot always be invoked properly

Things seem rather complicated with Java the language generics.

A method that takes an Object[] as an argument

   public static void objectArgs(Object[] args)

cannot be invoked on an array of primitive types

   int i[] = {42};
   objectArgs(i); // Doesn't compile

But the signature of the method originally in question declares the type of array to extend java.lang.Object:

   public static <T extends Object> List<T> asList(T[] ts) 

and *can* be invoked on an array of primitive types

   int i[] = {42};

Need to check exactly what kind of code is generated by javac here, but presumably the compiler somehow transforms the primitive array to wrapped type here?

So, JAVA:JSTATIC cannot make currently make a call that can be made in Java the language. Presumably JAVA:JCALL has the same sort of problem

From experimenting a bit, it would not be enough to fix Java.isApplicableMethod(). We would also at least have to extend Java.javaInstance(Class<?>) to return arrays of primitive types.

comment:5 in reply to:  1 Changed 9 years ago by Mark Evenson

Description: modified (diff)

Replying to

Simplest test-case:

(jss:jarray-to-list (java:jnew-array (jclass "int") 40))

Text of the original report:

#<jarray [B@5719d1 {15F987F}>
CL-USER> (jss:jarray-to-list *)


no such method

[Condition of type ERROR]


0: [RETRY] Retry SLIME REPL evaluation request.
1: [ABORT] Return to sldb level 1.
2: [RETRY] Retry SLIME REPL evaluation request.
3: [*ABORT] Return to SLIME's top level.
4: [ABORT] Abort thread.


0: (#<FUNCTION {149EEF3}> #<ERROR {E6942E}> #<FUNCTION {149EEF3}>)
1: (APPLY #<FUNCTION {149EEF3}> (#<ERROR {E6942E}> #<FUNCTION {149EEF3}>))
4: org.armedbear.lisp.Lisp.error(
5: org.armedbear.lisp.Java.jstatic(
6: org.armedbear.lisp.Java$pf_jstatic.execute(
7: org.armedbear.lisp.Primitive.execute(
8: (JSS:JARRAY-TO-LIST #<jarray [B@5719d1 {15F987F}>)

11: (SWANK::EVAL-REGION "(jss:jarray-to-list *)


Note: See TracTickets for help on using tickets.