#2367 Java FFI array access - raising NullErr

peterlane Fri 24 Oct 2014

I am working on a Fantom system which is using a Java library (for evolutionary computing). The system uses a Fantom front-end to drive the Java library, which also consumes Fantom classes.

Although the system is working well, I have run into an issue I don't understand, when accessing a field in a Java class containing an array. (The Java class is used by the library; the array contains Java objects which have references to instances of Fantom classes.)

The object is held in a field individual of the appropriate type (GPIndividual). If I try to access the field directly, using:

individual.trees

I get an exception sys::NullErr: java.lang.NullPointerException

If I access other fields directly, there is no problem.

The field is definitely present and accessible, as shown by the following calls and output:

echo ("$individual")
echo ("$individual.typeof.fields")

ec.gp.GPIndividual@2100573699{740130606}
[[java]ec.gp::GPIndividual.P_NUMTREES, [java]ec.gp::GPIndividual.P_TREE, 
 [java]ec.gp::GPIndividual.trees, [java]ec::Individual.P_INDIVIDUAL, 
 [java]ec::Individual.EVALUATED_PREAMBLE, [java]ec::Individual.fitness, 
 [java]ec::Individual.species, [java]ec::Individual.evaluated]

I can get at the field using either:

individual.typeof.field ("trees").get (individual)

or better:

individual->trees

I don't mind the dynamic access, but I'm puzzled why the non-array fields are directly accessible, but this field is not. The null exception took a while to work out.

This must be something to do with the library, as direct array access works with other simple examples I tried. But I would like to know what !??

Any ideas?

Login or Signup to reply.