Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8041663

Sensitive dependence on location of nested interface

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b14
    • CPU:
      x86_64
    • OS:
      linux
    • Verification:
      Verified

      Backports

        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 ----------

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jlahoda Jan Lahoda
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: