#2766 Invalid argument sys::Int for Java FFI

beatfreaker Tue 13 Aug

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

My Bad, setAmount() accepts Long

brian Tue 13 Aug

What does your compiler error look like?

SlimerDude Wed 14 Aug

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

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

setAmount( (Int?)val )

//  or maybe this

Obj? boxed := intVal
setAmount(boxed)

This worked, thanks Brian

Login or Signup to reply.