#2766 Invalid argument sys::Int for Java FFI

beatfreaker Tue 13 Aug 2019

I am using thirst party java library(stripe-java), and I am using Java FFI feature of fantom to call the API of this thirst party java library

There is this class in stripe-java library https://github.com/stripe/stripe-java/blob/master/src/main/java/com/stripe/param/ChargeCreateParams.java

which allows to create object using builder pattern

Now when I try to call a method setAmount(sys::Int) which accepts an Int fantom is giving me compiler time error even though I am passing Int

error snippet

beatfreaker Tue 13 Aug 2019

My Bad, setAmount() accepts Long

brian Tue 13 Aug 2019

What does your compiler error look like?

SlimerDude Wed 14 Aug 2019

The compiler error is as depicted in the screenshot:

Invalid args setAmount(sys::Int)

I can confirm this is an issue in Fantom 1.0.73:

using [java] com.stripe.param::ChargeCreateParams

...
ChargeCreateParams.builder.setAmount(150) // --> Invalid args setAmount(sys::Int)
...

The signature of setAmount() is:

public Builder setAmount(Long amount)

brian Wed 14 Aug 2019

I can't think of any Java APIs off the top of my head that take java.lang.Long, so can't quickly test myself. But sys::Int? (nullable) is the same as java.lang.Long, so try casting it like this:

setAmount( (Int?)val )

//  or maybe this

Obj? boxed := intVal
setAmount(boxed)

It might just a that the compiler isn't auto-boxing in that case

beatfreaker Thu 15 Aug 2019

setAmount( (Int?)val )

//  or maybe this

Obj? boxed := intVal
setAmount(boxed)

This worked, thanks Brian

go4 Thu 21 Nov 2019

It seems no java.lang.Long mapping. A fix like this

brian Mon 2 Mar 2020

I pushed a fix for that allow Fantom types to be used directly for their Java counterparts:

java.lang.Bool -> sys::Bool?
java.lang.Long -> sys::Int?
java.lang.Double -> sys::Float?

Login or Signup to reply.