This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Exception when calling fn. using for-each in Java


I'm having problems calling Kawa-compiled functions that
contain 'for-each' from Java. This is in Kawa 1.6.70.

Here's my test module, in test.scm:
  (module-name 'test)
  (module-static #t)
  (define (pairToVector list) <java.util.Vector>
    (let ( (v <java.util.Vector> (make <java.util.Vector>) ) 
         )
      (for-each (lambda (i)
                  (invoke v 'addElement i)
                )
                list
      )  
    v)
which defines pairToVector, a function intended to iterate
over a list and add its elements to a Java vector.

I compile it thus:
  java kawa.repl -d \. -P kb7.mm3.compiler. -C test.scm
(kb7.mm3.compiler is the package prefix for this project).

Then I Java-compile the program below, in test1.java:
  package kb7.mm3.compiler;
  import java.util.Vector;
  public class test1
  {
    public static final void main( String[] argv )
    {
      System.out.println( test.pairToVector(null) );
    }
  }
and call it:
  java kb7.mm3.compiler.test1

And I see the following exception:
  Exception in thread "main" java.lang.ExceptionInInitializerError: java.lang.Null
  PointerException
          at kb7.mm3.compiler.test.<clinit>(test.scm:5))
Line 5 is actually in the 'let': to save space, I omitted some blank lines 
in the Kawa listing above.

Now, this is NOT because I've passed a null parameter to pairToVector:
the same exception also happens if I construct a Kawa list and pass that.
By compiling various Kawa functions and calling from Java, I've discovered
that it's the presence of a for-each in the function that provokes this
error, whether or not it is acting on objects passed from Java. But such
functions work OK when called from Kawa. 

Tentative hypothesis: when Kawa compiles a 'for-each', it generates some 
kind of initialisation code which needs to be executed when the function 
is called for the first time. This is automatic when calling from Kawa, 
but not from Java. Any suggestions?

Jocelyn Paine
http://www.ifs.org.uk/~popx/
http://www.di.uminho.pt/~popx/
+44 (0)7768 534 091 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]