question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Reference to X is ambiguous" compiling Java code

See original GitHub issue

The Akka codebase includes some Java code resulting from code generation using protoc from .protobuf files. This Java code is kept under SCM (git) so it is not regenerated over and over.

A particular protobuf file uses protobuf inner messages that result into generating inner classes when producing Java classes for the protobuf messages. Each of the generated classes includes a Builder inner class.

Compiling code that uses those Builder classes produces the following compiler error:

[error] -- [E049] Reference Error: /Users/ignasi/git/github/akka/akka/akka-persistence-scala3/akka-persistence/src/main/java/akka/persistence/serialization/MessageFormats.java:4113:16 
[error] 4113 |      protected Builder newBuilderForType(
[error]      |                ^^^^^^^
[error]      |            Reference to Builder is ambiguous,
[error]      |            it is both defined in object AtLeastOnceDeliverySnapshot
[error]      |            and inherited subsequently in class UnconfirmedDelivery

when compiling this code. NOTE: this error is a sample, there are a few more identical to that one.

I already tried compiling java sources first as suggested offline by some colleagues (@lrytz) but that workaround is not feasible in this particular codebase, unfortunately, since there are other parts of the build that require compiling Scala first. Using Mixed compile ordering doesn’t work around the issue.

Compiler version

3.0.1-RC1

Minimized code

public final class MessageFormats {
    public  static final class AtLeastOnceDeliverySnapshot extends ... {
         public static final class Builder extends ... {
         }
         public  static final class UnconfirmedDelivery extends ... {
             public static final class Builder extends ... {
             }
             // code referring to `Builder` in this block will no longer 
             // compile in scala3
             @java.lang.Override
             protected Builder newBuilderForType(...) {
                  Builder builder = new Builder(parent);
                  return builder;
             }
             ...
         }
    }
}

Or probably smaller:

public final class A {
  public static final class C { }
  public static final class D {
    public static final class C { }
    public C foo() { return new C(); }
  }
}

Expectation

The compile can compile the Java code as it did in 2.13 and previous versions.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
smartercommented, Jul 19, 2021

3.0.1 was branched more than six weeks ago so it’s old news already 😉

0reactions
som-snyttcommented, Jul 19, 2021

sdkman is out of the loop.

➜  ~ sdk list scala
================================================================================
Available Scala Versions
================================================================================
 > * 3.0.0             * 2.12.10             2.11.6
   + 3.0.0-RC1           2.12.9              2.11.5
   + 3.0.0-M3          * 2.12.8              2.11.4
   + 3.0.0-M2          * 2.12.7              2.11.3
   + 3.0.0-M1          * 2.12.6            * 2.11.2
Read more comments on GitHub >

github_iconTop Results From Across the Web

"The method X is ambiguous for the type Y" Java ambiguous ...
You will get compile time error as The method foo(Object) is ambiguous for the type Test because both String and Integer class have...
Read more >
java - Reference to X is ambiguous, but compiles in Eclipse
Reference to X is ambiguous, but compiles in Eclipse ; static void main(String[] args) · MyTest ; test = new MyTest · public...
Read more >
Ambiguities in Java - GeeksforGeeks
The ambiguities are those issues that are not defined clearly in the Java language specification. The different results produced by ...
Read more >
JDK-8077243 Incorrect reference to method is ambiguous ...
JDK-8077243 : Incorrect reference to method is ambiguous when using lambdas and generics. Type: Bug; Component: tools; Sub-Component: javac ...
Read more >
Ambiguous base classes (C++ only) - IBM
Access to a base class member is ambiguous if you use a name or qualified name that does not refer to a unique...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found