Http.get is ambiguous from Java

Have I missed a new feature in Java that allows this type of call? My IDE (IntelliJ) doesn’t like it, though the compiler does accept it. I wasn’t able to find any documentation suggesting that it was actually legal now.

Mark

No warnings in latest IntelliJ for:

ActorSystem system = ActorSystem();
Http http = Http.get(system);

Have you perhaps gotten some imports wrong so you have the scaladsl version of Http in scope?

No, there is nothing from scaladsl. It is also the latest version of IntelliJ. IntelliJ decompiles Http as

package akka.http.javadsl;

public static Http get(ActorSystem var0) {
return Http$.MODULE$.get(var0);
}

public static Extension get(ActorSystem var0) {
return Http$.MODULE$.get(var0);
}

This is akka-http_2.12 version 10.1.0

The problem also occurs with HttpServerMinimalExampleTest just cut/pasted from the documentation.

That is indeed strange. I was in the Akka HTTP sources, but now I verified in a separate project depending on the Akka HTTP artifact, and I do not get a warning, also in latest IntelliJ here.

The method is supposed to be overridden and not occur two times, as that wouldn’t be valid Java code. Perhaps some form of IntelliJ bug?

The akka-http_2.12-10.1.0-sources.jar fetched from Maven central doesn’t contain any source for akka.http.javadsl.Http (neither java or scala). Is this class actually autogenerated in some way?

I wonder if something was wrong with the 10.1.0 release, I can confirm it misses those sources. Can you use 10.1.1 instead? It is the latest stable release, and it looks correct.

Exactly the same result - still no source and same error in IntelliJ

OK, the source is in akka-http-core and is scala.

Disassembling Http.class with javap (from Java 8) gives

public static akka.http.javadsl.Http get(akka.actor.ActorSystem);
public static akka.actor.Extension get(akka.actor.ActorSystem);

so the overload by return type is definitely present.

Installing scala support in IntelliJ eliminates the complaint - which is no doubt why it worked for you. This also allows the IDE to find the source.

Which exact artifact are you depending on? It may be better to depend on akka-http_2.12 if you’re on the 11 currently?

I just manually downloaded both:
https://repo1.maven.org/maven2/com/typesafe/akka/akka-http-core_2.11/10.1.1/akka-http-core_2.11-10.1.1-sources.jar
https://repo1.maven.org/maven2/com/typesafe/akka/akka-http-core_2.12/10.1.1/akka-http-core_2.12-10.1.1-sources.jar

And they both contain the akka/http/javadsl/Http.scala sources. So if you see the issue with 10.1.1 the problem is not related to missing sources, but there is something else going on.

If I look at the actual class-files for Akka HTTP 10.1.1 with javap, for 2.12, I can see:

public static akka.http.javadsl.Http get(akka.actor.ActorSystem);
public static akka.actor.Extension get(akka.actor.ActorSystem);

but for Scala 2.11 there is only the one, so it may be a Scala 2.12 bug emitting two methods in the companion object when we explicitly say override.

Got verified by Lukas Rytz on the Scala team that this is in fact a Java interop-bug: https://github.com/scala/bug/issues/10812

Thank you for your effort. Fortunately, with the Intellij Scala plugin installed, my project now looks clean of warnings.