-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eclipse java compiler gets confused by the new ACC_BRIDGE flag in forwarders #11271
Comments
Same problem exists in IntelliJ |
I think the same reasoning that motivated us to go back to 2.12.6 in scala/scala#7383 should also apply here? Is it feasible to revert fully to the 2.12.6 behavior? |
It will not work in JDK 11 if going back to exactly the same as in 2.12.6. It's also broken in IntelliJ with 2.12.6, and I'm surprised that we haven't heard more complaints about that. |
Ah right, thanks, rock and hard place. |
So, if we backport the 2.13 fix to 2.12.8, we can make both Java 11 and alternative Java 8 compilers happy, but it will mean new versions of akka compiled with 2.12.8 would not be drop in compatible. Java users would have to recompile against the new jars. @patriknw, what do you prefer? |
The 2.13 fix being scala/scala#6531 |
In above example there are two methods
Is the change in 2.13 to remove the forwarder for |
Yes, the change would remove the erased version of De-compiling |
As the person who "invented"/discovered this (now problematic) pattern, I'm
curious to see if/how we can solve it.
|
@lrytz what does JDT (Eclipse) generate?
|
It doesn't genarte anything as the compiler issues an error. Actually, without the |
In 2.12.6 and before, the Scala compiler emits static forwarders for bridge methods in top-level modules. These forwarders are emitted by mistake, the filter to exclude bridges did not work as expected. These bridge forwarders make the Java compiler on JDK 11 report ambiguity errors when using static forwarders (scala/bug#11061). PR scala#7035 fixed this for 2.12.7 by adding the `ACC_BRIDGE` flag to static forwarders for bridges. We decided to keep these bridges for binary compatibility. However, the new flag causes the eclipse Java compiler (and apparently also IntelliJ) to report ambiguity errors when using static forwarders (scala/bug#11271). In 2.13.x the Scala compiler no longer emits static forwarders for bridges (PR scala#6531). This PR brings the same behavior to 2.12.8. This change breaks binary compatibility. However, in the examples we tested, the Java compiler emits references to the non-bridge methods, so compiled code continues to work if a library is replaced by a new version that doesn't have forwarders for bridges: ``` $> cat T.scala class A[T] { def get: T = ??? } object T extends A[String] { override def get: String = "hi" } $> ~/scala/scala-2.12.7/bin/scalac T.scala ``` Generates two forwarders in `T.class` ``` // access flags 0x49 public static bridge get()Ljava/lang/Object; // access flags 0x9 public static get()Ljava/lang/String; ``` ``` $> javac -version javac 1.8.0_181 $> cat Test.java public class Test { public static void main(String[] args) { System.out.println(T.get()); } } $> javac Test.java ``` Generates in Test.class ``` INVOKESTATIC T.get ()Ljava/lang/String; ```
@patriknw I created a PR with the change to remove forwarders for bridges. Could you test with version If you have a way to build akka with that version and drop in the jars into some project (which uses the static forwarders) compiled against a previous version of akka, that would give us some confidence for the assumption that the bridge forwarders are not actually used. |
I will try it, thanks. |
I have tested 2.12.8-bin-3edeaac-SNAPSHOT and it works. For binary compatibility verification I used
Tried same thing with Akka 2.5.17 (which was built with Scala 2.12.6). Tried https://github.com/patriknw/akka-compile-ide-java in both Eclipse and IntelliJ (no Scala plugins installed) and they are both happy. |
Thank you for testing! |
This bug affects Akka users that write Java code in eclipse. They get error messages in the IDE ("The method get(ActorSystem) is ambiguous").
To reproduce, download ecj-4.9.jar from http://download.eclipse.org/eclipse/downloads/drops4/R-4.9-201809060745/#JDTCORE
T.scala
Test.java
With 2.12.6:
2.12.6 generates the following static methods in
T.class
:With 2.12.7 and current 2.12.x (2.12.8-bin-25c7215):
Generated methods in
T.class
:The bytecode change is exactly as intended by PR scala/scala#7035 that went to 2.12.7. The follow-up PR scala/scala#7383 that went into 2.12.x fixes a different bug and does not change anything here.
Someone predicted that something like this could happen.
The text was updated successfully, but these errors were encountered: