#2246 Java FFI: ClassFormatError: Illegal class name

kjauslin Thu 27 Feb 2014

This works:

using [java] org.apache.poi.hssf.usermodel::HSSFSheet
HSSFSheet? sheet := workbook.getSheet(sheetName)

This does not work:

using [java] org.apache.poi.hssf.usermodel::HSSFSheet
HSSFSheet? sheet := workbook.getSheet(sheetName)
sheet = workbook.getSheet(sheetName)

Any ideas? It looks like it's not possible to reassign a java class reference.

Update the code will just not work if it's inside a closure (e.g. iterator list.each)! So, does FFI generally not work if used inside closures? Update if it's used inside a closure, the function will fail at runtime, even if the code is not reached!

The following exception is thrown:

java.lang.ClassFormatError: Illegal class name   "fan/myExt/Wrap$[java]org.apache.poi.hssf.usermodel$HSSFSheet$n" in class file fan/myExt/ApachePOI
 	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at fan.sys.FanClassLoader.findPendingClass(FanClassLoader.java:130)
	at fan.sys.FanClassLoader.findClass(FanClassLoader.java:88)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at fan.sys.FanClassLoader.loadFan(FanClassLoader.java:57)
	at fan.sys.BootEnv.loadTypeClasses(BootEnv.java:265)
	at fan.sys.Env.loadTypeClasses(Env.java:206)
	at fan.sys.ClassType.emit(ClassType.java:490)
	at fan.sys.ClassType.finish(ClassType.java:544)
	at fan.sys.Method$MethodFunc.isStatic(Method.java:475)
	at fan.sys.Method$MethodFunc.callList(Method.java:191)
	at fan.sys.Method.callList(Method.java:138)
	at fanx.tools.Fan.callMain(Fan.java:173)
	at fanx.tools.Fan.executeType(Fan.java:140)
	at fanx.tools.Fan.execute(Fan.java:41)
	at fanx.tools.Fan.run(Fan.java:298)
	at fanx.tools.Fan.main(Fan.java:336)
sys::Err: Method not mapped to java.lang.reflect correctly myExt::ApachePOI.main
fan.sys.Method$MethodFunc.isStatic (Method.java:482)
fan.sys.Method$MethodFunc.callList (Method.java:191)
fan.sys.Method.callList (Method.java:138)
fanx.tools.Fan.callMain (Fan.java:173)
fanx.tools.Fan.executeType (Fan.java:140)
fanx.tools.Fan.execute (Fan.java:41)
fanx.tools.Fan.run (Fan.java:298)
fanx.tools.Fan.main (Fan.java:336)

SlimerDude Thu 27 Feb 2014

It looks like it's not possible to reassign a java class reference.

Um, try not to reassign it - instead try assigning it to a new variable:

HSSFSheet? sheet1 := workbook.getSheet(sheetName)
HSSFSheet? sheet2 := workbook.getSheet(sheetName)

I know though debugging Fantom, if you re-assign a method parameter then it gets declared as wrapped variable - which seems to be what you're having trouble with.

If you don't reassign it, then the Wrap variable is never created.

Granted, what you wrote should work - but my Java FFI knowledge is very limited. (I did Fancom and that's about it!)

brian Thu 27 Feb 2014

Promoted to ticket #2246 and assigned to brian

That is a bug. It appears that you probably have the Java FFI class setup as a mutating variable inside a closure. Then we auto-generate an invalid name for the wrapper class used to share the reference. In the meantime, if you keep that sheet reference immutable then it should work.

kjauslin Thu 27 Feb 2014

Thanks, good to know. I worked around it using a for loop - where it works.

brian Thu 8 Jan 2015

Ticket resolved in 1.0.67

The closure wrapper classes generated by the compiler are named using the fully qualified type name of the value being wrapped. In the case of Java FFI this was causing an invalid name. The compiler has been fixed to handle the special chars that might show up such as [java]java.util in a pod name.

Login or Signup to reply.