twitter/util

Java interop with finagle 7 emits "malformed variable arity method: addGauge$"

devshorts opened this issue · 5 comments

In working to update finagle zipkin to finagle 7 (openzipkin/zipkin-finagle#35) we are seeing that the compiler complains about a malformed variable arity method: addGauge$

Expected behavior

Compilation succeeds

Actual behavior

Compilation fails

Steps to reproduce the behavior

The project in the PR easily reproduces the issue by just accessing import com.twitter.finagle.stats.StatsReceiver; in java. The full compilation error is:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/devshorts/src/zipkin-finagle/core/src/main/java/zipkin/finagle/ReporterMetricsAdapter.java:[18,33] cannot access com.twitter.finagle.stats.StatsReceiver
  bad class file: /Users/devshorts/.m2/repository/com/twitter/util-stats_2.12/7.0.0/util-stats_2.12-7.0.0.jar(/com/twitter/finagle/stats/StatsReceiver.class)
    class file contains malformed variable arity method: addGauge$(com.twitter.finagle.stats.StatsReceiver,java.lang.String[],scala.Function0)
    Please remove or make sure it appears in the correct subdirectory of the classpath.
[INFO] 1 error

Thanks @devshorts!

I downloaded the util-stats-7.0.0 package for 2.12 and checked it against javap. Indeed there is a static addGauge$ method there: https://gist.github.com/vkostyukov/1ac96e29684c7345bd16d2db59c1d732

I honestly have no idea why

  1. scalac generated that static forwarder
  2. javac isn't happy about it

Will keep digging.

FWIW, I can reproduce it on my end (by pulling in that zipkin-finagle PR).

To be frank, this "class file contains malformed variable arity method" is quite a surprise to me - I've never seen anything like that before so the rest of the internet (try googling it). I wonder if it's somehow only specific to zipkin-finagle. We should try creating an empty Java (maven) project from scratch that referencing StatsReceiver. @devshorts Any chance you want to try that out?

I'm getting somewhere. These $-prefixed methods are coming from Scala 2.12. Here is the relevant piece of SR compiled against 2.11.11:

  public abstract com.twitter.finagle.stats.Gauge addGauge(java.lang.String..., scala.Function0<java.lang.Object>);
  public abstract com.twitter.finagle.stats.Gauge addGauge(com.twitter.finagle.stats.Verbosity, java.lang.String..., scala.Function0<java.lang.Object>);
  public abstract com.twitter.finagle.stats.Gauge addGauge(scala.collection.Seq<java.lang.String>, scala.Function0<java.lang.Object>);
  public abstract com.twitter.finagle.stats.Gauge addGauge(com.twitter.finagle.stats.Verbosity, scala.collection.Seq<java.lang.String>, scala.Function0<java.lang.Object>);

Here is the same, but for Scala 2.12.1:

  public static com.twitter.finagle.stats.Gauge addGauge$(com.twitter.finagle.stats.StatsReceiver, java.lang.String..., scala.Function0);
  public com.twitter.finagle.stats.Gauge addGauge(java.lang.String..., scala.Function0<java.lang.Object>);
  public static com.twitter.finagle.stats.Gauge addGauge$(com.twitter.finagle.stats.StatsReceiver, com.twitter.finagle.stats.Verbosity, java.lang.String..., scala.Function0);
  public com.twitter.finagle.stats.Gauge addGauge(com.twitter.finagle.stats.Verbosity, java.lang.String..., scala.Function0<java.lang.Object>);

  public static com.twitter.finagle.stats.Gauge addGauge$(com.twitter.finagle.stats.StatsReceiver, scala.collection.Seq, scala.Function0);
  public com.twitter.finagle.stats.Gauge addGauge(scala.collection.Seq<java.lang.String>, scala.Function0<java.lang.Object>);
  public abstract com.twitter.finagle.stats.Gauge addGauge(com.twitter.finagle.stats.Verbosity, scala.collection.Seq<java.lang.String>, scala.Function0<java.lang.Object>);

@kevinoliver pointed out that this could be related to 58c1d00 so var-arg isn't in the final position now. yet we have a Java compilation test that compiles perfectly with both 2.11 and 2.12.

@vkostyukov haha yeah, this one was ungoogleable, I tried too :). Glad to see you're making progress, I was trying to get maven based java sample to replicate it too and having kind of a hard time

We hope this should be fixed by 7e5024b. We're cutting a new Finagle/Util release quite soon so you can upgrade directly to 7.1.

Thanks @devshorts for filing an issue!