RESOLVED: Java Interop: Unable to call some class methods with 1.0.0-beta-3595 and Apache POI 3.13

Hi,

Thanks for developing and releasing Kotlin to the public. It’s a great language which is a pleasure to use.

I have been unable to call some methods from objects created with the TIBCO HAWK proprietary JAR. I don’t have permission to provide the JAR file for replication testing, but I think I’ve found an open-source library with which to replicate the error:

Apache POI 3.13 from http://poi.apache.org/

I’m able to create an object and call a couple of the object’s methods with Jython 2.1:

kewoo@AUD31304KZ C:\u
$ java -Xmx256M -Xms32M -noverify -cp jython-2.1.jar;c:\u\poi-3.13\poi-3.13-20150929.jar;c:\u\poi-3.13\poi-examples-3.13-20150929.jar;c:\u\poi-3.13\poi-excelant-3.13-20150929.jar;c:\u\poi-3.13\poi-ooxml-3;13-20150929.jar;c:\u\poi-3.13\poi-ooxml-schemas-3.13-20150929.jar;c:\u\poi-3.13\poi-scratchpad-3.13-20150929.jar org.python.util.jython
Jython 2.1 on java1.7.0_07 (JIT: null)
>>> from org.apache.poi.ss.util import CellReference
>>> from org.apache.poi.ss.util import AreaReference
>>> x = CellReference(1,2)
>>> x.isPartAbsolute("a1")
0
>>> x.convertColStringToIndex("c1")
62
>>> ^Z

However, when I try to make the same method calls with Kotlin Beta 3:

kewoo@AUD31304KZ C:\u\kotlin-compiler-1.0.0-beta-3595\kotlinc\bin
$ java -Xmx256M -Xms32M -noverify  -cp ..\lib\kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp ..\lib\kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -cp ..\lib\kotlin-reflect.jar;c:\u\poi-3.13\poi-3.13-20150929.jar;c:\u\poi-3.13\poi-examples-3.13-20150929.jar;c:\u\poi-3.13\poi-excelant-3.13-20150929.jar;c:\u\poi-3.13\poi-ooxml-3.13-20150929.jar;c:\u\poi-3.13\poi-ooxml-schemas-3.13-20150929.jar;c:\u\poi-3.13\poi-scratchpad-3.13-20150929.jar
Welcome to Kotlin version 1.0.0-beta-3595 (JRE 1.7.0_07-b10)
Type :help for help, :quit for quit
>>> import org.apache.poi.ss.util.CellReference
>>> var x = CellReference(1,2)
>>> x.convertColStringToIndex("c1")
error: unresolved reference: convertColStringToIndex
x.convertColStringToIndex("c1")
  ^

>>> x.isPartAbsolute("a1")
error: unresolved reference: isPartAbsolute
x.isPartAbsolute("a1")
  ^

>>>

I used the javaClass.getMethods() to see if the methods were present and this output led me to believe the isPartAbsolute() and convertColStringToIndex() methods were available for me to call:

>>> x.javaClass.getMethods().map{println(it)}
public boolean org.apache.poi.ss.util.CellReference.equals(java.lang.Object)
public java.lang.String org.apache.poi.ss.util.CellReference.toString()
public int org.apache.poi.ss.util.CellReference.hashCode()
public int org.apache.poi.ss.util.CellReference.getRow()
public short org.apache.poi.ss.util.CellReference.getCol()
public java.lang.String org.apache.poi.ss.util.CellReference.getSheetName()
public boolean org.apache.poi.ss.util.CellReference.isRowAbsolute()
public boolean org.apache.poi.ss.util.CellReference.isColAbsolute()
public static boolean org.apache.poi.ss.util.CellReference.isPartAbsolute(java.lang.String)
public static int org.apache.poi.ss.util.CellReference.convertColStringToIndex(java.lang.String)
public static org.apache.poi.ss.util.CellReference$NameType org.apache.poi.ss.util.CellReference.classifyCellReference(java.lang.String,org.apache.poi.ss.SpreadsheetVersion)
public static boolean org.apache.poi.ss.util.CellReference.cellReferenceIsWithinRange(java.lang.String,java.lang.String,org.apache.poi.ss.SpreadsheetVersion)
public static boolean org.apache.poi.ss.util.CellReference.isColumnWithnRange(java.lang.String,org.apache.poi.ss.SpreadsheetVersion)
public static boolean org.apache.poi.ss.util.CellReference.isRowWithnRange(java.lang.String,org.apache.poi.ss.SpreadsheetVersion)
public static java.lang.String org.apache.poi.ss.util.CellReference.convertNumToColString(int)
public java.lang.String org.apache.poi.ss.util.CellReference.formatAsString()
public java.lang.String[] org.apache.poi.ss.util.CellReference.getCellRefParts()
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
[kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit, kotlin.Unit]
>>>

I’ve been experiencing similar symptoms with some (but not all) method calls from objects generated from the TIBCO HAWK Java API libraries. I hope that if this error is replicable with the publicly accessible Apache POI 3.13, then perhaps the problem will also be solved for the TIBCO HAWK Java API libraries too.

I currently don’t have a Kotlin workaround for calling these methods. I’ll continue using Jython to access the methods I need. Having said that, I enjoy the Kotlin syntax more than the Jython syntax so my decision to revert to using Jython has been made with reluctance.

Once again, thanks for developing Kotlin and releasing it to the public. Any feedback is appreciated.

Regards,

Kevin

I made another rookie mistake. The methods I was trying to call were static methods, not object methods:

kewoo@AUD31304KZ C:\u\kotlin-compiler-1.0.0-beta-3595\kotlinc\bin
$ java -Xmx256M -Xms32M -noverify  -cp ..\lib\kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp ..\lib\kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -cp ..\lib\kotlin-reflect.jar;C:\u\poi-3.13\poi-3.13-20150929.jar;c:\u\poi-3.13\poi-ooxml-3.13-20150929.jar;c:\u\poi-3.13\poi-ooxml-schemas-3.13-20150929.jar
Welcome to Kotlin version 1.0.0-beta-3595 (JRE 1.7.0_07-b10)
Type :help for help, :quit for quit
>>> import org.apache.poi.ss.util.CellReference
>>> CellReference.convertColStringToIndex("c1")
62
>>> CellReference.isPartAbsolute("a1")
false
>>>