JDK-8041663 : Sensitive dependence on location of nested interface
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-04-22
  • Updated: 2014-07-29
  • Resolved: 2014-05-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b14Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux sandy 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Compilation of the attached source causes the attached error, but moving the SourceWrapper interface lower in the file (as indicated by the comment) causes the compilation to succeed.  I'm not at all sure whether the error should even be happening in the first place, since it was compiling fine in JDK7.

REGRESSION.  Last worked in version 7u25

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1~deb7u1)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No errors expected.
ACTUAL -
$ javac ./scratch/Main.java

./scratch/Main.java:41: error: reference to with is ambiguous
    channel.with(s);
           ^
  both method with(AccessStrategy) in SinkWrapper and method with(AccessStrategy) in SourceWrapper match
1 error


ERROR MESSAGES/STACK TRACES THAT OCCUR :
./scratch/Main.java:41: error: reference to with is ambiguous
    channel.with(s);
           ^
  both method with(AccessStrategy) in SinkWrapper and method with(AccessStrategy) in SourceWrapper match
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package scratch;

public class Main {
  public interface SinkStrategy { }

  public interface AccessStrategy extends SinkStrategy { }

  public interface Strategy extends AccessStrategy { }

  public interface Source extends SourceWrapper { }

  public interface SourceWrapper {
    Source with(AccessStrategy strategy);
  }

  public interface SinkWrapper {
    Sink with(SinkStrategy strategy);
    Sink with(AccessStrategy strategy);
  }

  // --> moving SourceWrapper to here causes compilation to succeed

  public interface Sink extends Source, SinkWrapper { }

  public static class Channel implements Sink {
    @Override
    public Sink with(AccessStrategy strategy) {
      System.out.println("access  " + strategy);
      return null;
    }
    @Override
    public Sink with(SinkStrategy strategy) {
      System.out.println("sink " + strategy);
      return null;
    }
  }

  public static void main(String[] args) {
    final Sink channel = new Channel();
    final Strategy s = new Strategy() { };
    channel.with(s);
  }
}
---------- END SOURCE ----------


Comments
ManualVerify: Bug verified manually in promoted results for build JDK9-b14
08-07-2014

Reproducible with 8, 8u20b and 9b10.
24-04-2014