Search code examples
scalafinagletwitter-finagle

no suitable method found for configured finagle in Java code


I've Java polyglot application which mainly has Java code and uses few Scala libraries as well.

The Scala below code compiles fine.

import com.twitter.finagle.Http.Client
import com.twitter.finagle.Http
import com.twitter.finagle.param.Logger

object Main extends App {

  private val loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger")

  val client: Client = Http.client
    .configured(Logger(loggerFinagle))
}

I write the same code in java as below

import com.twitter.finagle.Http;
import com.twitter.finagle.param.Logger;

public class JavaMain {
    public static void main(String[] args) {

        java.util.logging.Logger loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger");

        Http.client()
               .configured(new Logger(loggerFinagle));
    }
}

When I compile the code I get below error -

[info] Compiling 1 Scala source and 1 Java source to /Users/rajkumar.natarajan/Documents/Coding/finagle-errors/target/scala-2.12/classes ...
[error] /Users/rajkumar.natarajan/Documents/Coding/finagle-errors/src/main/java/JavaMain.java:10:1: no suitable method found for configured(com.twitter.finagle.param.Logger)
[error]     method com.twitter.finagle.Stack.Parameterized.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (actual and formal argument lists differ in length))
[error]     method com.twitter.finagle.Stack.Parameterized.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error]     method com.twitter.finagle.client.StackClient.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (actual and formal argument lists differ in length))
[error]     method com.twitter.finagle.client.StackClient.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error]     method com.twitter.finagle.client.EndpointerStackClient.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (actual and formal argument lists differ in length))
[error]     method com.twitter.finagle.client.EndpointerStackClient.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error]     method com.twitter.finagle.Http.Client.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error]       (cannot infer type-variable(s) P
[error]         (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error] Http.client()
[error]                .configured

Looks like I've to pass the Tuple but I don't know how.

The project in github is here.

Below are dependency details of my project -

Scala Version - 2.12.6

Java Version - 1.8.0_151

finagle version - 7.1.0


Solution

  • According to the docs, you need to call the mk() method on the param, so something like the following should create the proper tuple:

        Http.client()
               .configured(new Logger(loggerFinagle).mk());