8030855: Default methods should be visible under source previous to 8 jdk8u20-b01

Thu, 06 Feb 2014 21:11:27 +0000

author
vromero
date
Thu, 06 Feb 2014 21:11:27 +0000
changeset 2261
79dc4b992c0a
parent 2260
fb870c70e774
child 2262
26b33a6ea088
child 2264
66245d9d84db

8030855: Default methods should be visible under source previous to 8
Reviewed-by: jjg, dlsmith

src/share/classes/com/sun/tools/javac/code/Source.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/T8029240/DefaultMethodsNotVisibileForSource7Test.java file | annotate | diff | comparison | revisions
test/tools/javac/defaultMethodsVisibility/DefaultMethodsNotVisibleForSourceLessThan8Test.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java	Thu Feb 06 21:03:03 2014 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java	Thu Feb 06 21:11:27 2014 +0000
     1.3 @@ -203,9 +203,6 @@
     1.4      public boolean allowDefaultMethods() {
     1.5          return compareTo(JDK1_8) >= 0;
     1.6      }
     1.7 -    public boolean allowDefaultMethodsResolution() {
     1.8 -        return compareTo(JDK1_7) >= 0;
     1.9 -    }
    1.10      public boolean allowStaticInterfaceMethods() {
    1.11          return compareTo(JDK1_8) >= 0;
    1.12      }
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 06 21:03:03 2014 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 06 21:11:27 2014 +0000
     2.3 @@ -92,10 +92,9 @@
     2.4      TreeInfo treeinfo;
     2.5      Types types;
     2.6      JCDiagnostic.Factory diags;
     2.7 -    public final boolean boxingEnabled; // = source.allowBoxing();
     2.8 -    public final boolean varargsEnabled; // = source.allowVarargs();
     2.9 +    public final boolean boxingEnabled;
    2.10 +    public final boolean varargsEnabled;
    2.11      public final boolean allowMethodHandles;
    2.12 -    public final boolean allowDefaultMethodsResolution;
    2.13      public final boolean allowStructuralMostSpecific;
    2.14      private final boolean debugResolve;
    2.15      private final boolean compactMethodDiags;
    2.16 @@ -137,7 +136,6 @@
    2.17          verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
    2.18          Target target = Target.instance(context);
    2.19          allowMethodHandles = target.hasMethodHandles();
    2.20 -        allowDefaultMethodsResolution = source.allowDefaultMethodsResolution();
    2.21          allowStructuralMostSpecific = source.allowStructuralMostSpecific();
    2.22          polymorphicSignatureScope = new Scope(syms.noSymbol);
    2.23  
    2.24 @@ -1681,7 +1679,6 @@
    2.25                  bestSoFar : methodNotFound;
    2.26  
    2.27          for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) {
    2.28 -            if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethodsResolution) break;
    2.29              //keep searching for abstract methods
    2.30              for (Type itype : itypes[iphase2.ordinal()]) {
    2.31                  if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
    2.32 @@ -1714,10 +1711,8 @@
    2.33                  //from superinterfaces)
    2.34                  if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) {
    2.35                      return this;
    2.36 -                } else if (rs.allowDefaultMethodsResolution) {
    2.37 +                } else {
    2.38                      return DEFAULT_OK;
    2.39 -                } else {
    2.40 -                    return null;
    2.41                  }
    2.42              }
    2.43          },
    2.44 @@ -3341,9 +3336,9 @@
    2.45              if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
    2.46              env1 = env1.outer;
    2.47          }
    2.48 -        if (allowDefaultMethodsResolution && c.isInterface() &&
    2.49 -                name == names._super && !isStatic(env) &&
    2.50 -                types.isDirectSuperInterface(c, env.enclClass.sym)) {
    2.51 +        if (c.isInterface() &&
    2.52 +            name == names._super && !isStatic(env) &&
    2.53 +            types.isDirectSuperInterface(c, env.enclClass.sym)) {
    2.54              //this might be a default super call if one of the superinterfaces is 'c'
    2.55              for (Type t : pruneInterfaces(env.enclClass.type)) {
    2.56                  if (t.tsym == c) {
     3.1 --- a/test/tools/javac/T8029240/DefaultMethodsNotVisibileForSource7Test.java	Thu Feb 06 21:03:03 2014 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,164 +0,0 @@
     3.4 -/*
     3.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 - *
     3.8 - * This code is free software; you can redistribute it and/or modify it
     3.9 - * under the terms of the GNU General Public License version 2 only, as
    3.10 - * published by the Free Software Foundation.
    3.11 - *
    3.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 - * version 2 for more details (a copy is included in the LICENSE file that
    3.16 - * accompanied this code).
    3.17 - *
    3.18 - * You should have received a copy of the GNU General Public License version
    3.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 - *
    3.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 - * or visit www.oracle.com if you need additional information or have any
    3.24 - * questions.
    3.25 - */
    3.26 -
    3.27 -/*
    3.28 - * @test
    3.29 - * @bug 8029240
    3.30 - * @summary Default methods not always visible under -source 7
    3.31 - * @library /tools/javac/lib
    3.32 - * @build ToolBox
    3.33 - * @run main DefaultMethodsNotVisibileForSource7Test
    3.34 - */
    3.35 -
    3.36 -import java.nio.file.Files;
    3.37 -import java.nio.file.Paths;
    3.38 -
    3.39 -public class DefaultMethodsNotVisibileForSource7Test {
    3.40 -    // common definitions
    3.41 -
    3.42 -    // this one should be compiled with source 8, the rest with source 7
    3.43 -    static final String ISrc =
    3.44 -        "interface I {\n" +
    3.45 -        "    default void m() {}\n" +
    3.46 -        "}";
    3.47 -
    3.48 -    static final String JSrc =
    3.49 -        "interface J extends I {}";
    3.50 -
    3.51 -    static final String ASrc =
    3.52 -        "abstract class A implements I {}";
    3.53 -
    3.54 -    static final String BSrc =
    3.55 -        "class B implements I {}";
    3.56 -
    3.57 -    // test legacy implementations
    3.58 -    static final String C1Src =
    3.59 -        "class C1 implements I {\n" +
    3.60 -        "    @Override public void m() {}\n" +
    3.61 -        "}";
    3.62 -
    3.63 -    static final String C2Src =
    3.64 -        "class C2 implements J {\n" +
    3.65 -        "    @Override public void m() {}\n" +
    3.66 -        "}";
    3.67 -
    3.68 -    static final String C3Src =
    3.69 -        "class C3 extends A {\n" +
    3.70 -        "    @Override public void m() {}\n" +
    3.71 -        "}";
    3.72 -
    3.73 -    static final String C4Src =
    3.74 -        "class C4 extends B {\n" +
    3.75 -        "    @Override public void m() {}\n" +
    3.76 -        "}";
    3.77 -
    3.78 -    //test legacy invocations
    3.79 -    static final String LegacyInvocationSrc =
    3.80 -        "class LegacyInvocation {\n" +
    3.81 -        "    public static void test(I i, J j, A a, B b) {\n" +
    3.82 -        "        i.m();\n" +
    3.83 -        "        j.m();\n" +
    3.84 -        "        a.m();\n" +
    3.85 -        "        b.m();\n" +
    3.86 -        "    }\n" +
    3.87 -        "}";
    3.88 -
    3.89 -    //test case super invocations
    3.90 -    static final String SubASrc =
    3.91 -        "class SubA extends A {\n" +
    3.92 -        "    public void test() {\n" +
    3.93 -        "        super.m();\n" +
    3.94 -        "    }\n" +
    3.95 -        "}";
    3.96 -
    3.97 -    static final String SubBSrc =
    3.98 -        "class SubB extends B {\n" +
    3.99 -        "    public void test() {\n" +
   3.100 -        "        super.m();\n" +
   3.101 -        "    }\n" +
   3.102 -        "}";
   3.103 -
   3.104 -    public static void main(String[] args) throws Exception {
   3.105 -        new DefaultMethodsNotVisibileForSource7Test().run();
   3.106 -    }
   3.107 -
   3.108 -    void run() throws Exception {
   3.109 -        testsPreparation();
   3.110 -        testLegacyImplementations();
   3.111 -        testLegacyInvocations();
   3.112 -        testSuperInvocations();
   3.113 -    }
   3.114 -
   3.115 -    void testsPreparation() throws Exception {
   3.116 -        Files.createDirectory(Paths.get("out"));
   3.117 -
   3.118 -        /* as an extra check let's make sure that interface 'I' can't be compiled
   3.119 -         * with source 7
   3.120 -         */
   3.121 -        ToolBox.JavaToolArgs javacArgs =
   3.122 -                new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)
   3.123 -                .setOptions("-d", "out", "-source", "7")
   3.124 -                .setSources(ISrc);
   3.125 -        ToolBox.javac(javacArgs);
   3.126 -
   3.127 -        //but it should compile with source >= 8
   3.128 -        javacArgs =
   3.129 -                new ToolBox.JavaToolArgs()
   3.130 -                .setOptions("-d", "out")
   3.131 -                .setSources(ISrc);
   3.132 -        ToolBox.javac(javacArgs);
   3.133 -
   3.134 -        javacArgs =
   3.135 -                new ToolBox.JavaToolArgs()
   3.136 -                .setOptions("-cp", "out", "-d", "out", "-source", "7")
   3.137 -                .setSources(JSrc, ASrc, BSrc);
   3.138 -        ToolBox.javac(javacArgs);
   3.139 -    }
   3.140 -
   3.141 -    void testLegacyImplementations() throws Exception {
   3.142 -        //compile C1-4
   3.143 -        ToolBox.JavaToolArgs javacArgs =
   3.144 -                new ToolBox.JavaToolArgs()
   3.145 -                .setOptions("-cp", "out", "-d", "out", "-source", "7")
   3.146 -                .setSources(C1Src, C2Src, C3Src, C4Src);
   3.147 -        ToolBox.javac(javacArgs);
   3.148 -    }
   3.149 -
   3.150 -    void testLegacyInvocations() throws Exception {
   3.151 -        //compile LegacyInvocation
   3.152 -        ToolBox.JavaToolArgs javacArgs =
   3.153 -                new ToolBox.JavaToolArgs()
   3.154 -                .setOptions("-cp", "out", "-d", "out", "-source", "7")
   3.155 -                .setSources(LegacyInvocationSrc);
   3.156 -        ToolBox.javac(javacArgs);
   3.157 -    }
   3.158 -
   3.159 -    void testSuperInvocations() throws Exception {
   3.160 -        //compile SubA, SubB
   3.161 -        ToolBox.JavaToolArgs javacArgs =
   3.162 -                new ToolBox.JavaToolArgs()
   3.163 -                .setOptions("-cp", "out", "-d", "out", "-source", "7")
   3.164 -                .setSources(SubASrc, SubBSrc);
   3.165 -        ToolBox.javac(javacArgs);
   3.166 -    }
   3.167 -}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/defaultMethodsVisibility/DefaultMethodsNotVisibleForSourceLessThan8Test.java	Thu Feb 06 21:11:27 2014 +0000
     4.3 @@ -0,0 +1,180 @@
     4.4 +/*
     4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @bug 8029240 8030855
    4.30 + * @summary Default methods not always visible under -source 7
    4.31 + * Default methods should be visible under source previous to 8
    4.32 + * @library /tools/javac/lib
    4.33 + * @build ToolBox
    4.34 + * @run main DefaultMethodsNotVisibleForSourceLessThan8Test
    4.35 + */
    4.36 +
    4.37 +import java.nio.file.Files;
    4.38 +import java.nio.file.Paths;
    4.39 +
    4.40 +public class DefaultMethodsNotVisibleForSourceLessThan8Test {
    4.41 +    // common definitions
    4.42 +
    4.43 +    // this one should be compiled with source 8, the rest with source < 8
    4.44 +    static final String ISrc =
    4.45 +        "interface I {\n" +
    4.46 +        "    default void m() {}\n" +
    4.47 +        "}";
    4.48 +
    4.49 +    static final String JSrc =
    4.50 +        "interface J extends I {}";
    4.51 +
    4.52 +    static final String ASrc =
    4.53 +        "abstract class A implements I {}";
    4.54 +
    4.55 +    static final String BSrc =
    4.56 +        "class B implements I {}";
    4.57 +
    4.58 +    // test legacy implementations
    4.59 +    static final String C1Src =
    4.60 +        "class C1 implements I {\n" +
    4.61 +        "    public void m() {}\n" +
    4.62 +        "}";
    4.63 +
    4.64 +    static final String C2Src =
    4.65 +        "class C2 implements J {\n" +
    4.66 +        "    public void m() {}\n" +
    4.67 +        "}";
    4.68 +
    4.69 +    static final String C3Src =
    4.70 +        "class C3 extends A {\n" +
    4.71 +        "    public void m() {}\n" +
    4.72 +        "}";
    4.73 +
    4.74 +    static final String C4Src =
    4.75 +        "class C4 extends B {\n" +
    4.76 +        "    public void m() {}\n" +
    4.77 +        "}";
    4.78 +
    4.79 +    //test legacy invocations
    4.80 +    static final String LegacyInvocationSrc =
    4.81 +        "class LegacyInvocation {\n" +
    4.82 +        "    public static void test(I i, J j, A a, B b) {\n" +
    4.83 +        "        i.m();\n" +
    4.84 +        "        j.m();\n" +
    4.85 +        "        a.m();\n" +
    4.86 +        "        b.m();\n" +
    4.87 +        "    }\n" +
    4.88 +        "}";
    4.89 +
    4.90 +    //test case super invocations
    4.91 +    static final String SubASrc =
    4.92 +        "class SubA extends A {\n" +
    4.93 +        "    public void test() {\n" +
    4.94 +        "        super.m();\n" +
    4.95 +        "    }\n" +
    4.96 +        "}";
    4.97 +
    4.98 +    static final String SubBSrc =
    4.99 +        "class SubB extends B {\n" +
   4.100 +        "    public void test() {\n" +
   4.101 +        "        super.m();\n" +
   4.102 +        "    }\n" +
   4.103 +        "}";
   4.104 +
   4.105 +    public static void main(String[] args) throws Exception {
   4.106 +        String[] sources = new String[] {
   4.107 +            "1.2",
   4.108 +            "1.3",
   4.109 +            "1.4",
   4.110 +            "1.5",
   4.111 +            "1.6",
   4.112 +            "1.7",
   4.113 +        };
   4.114 +        for (String source : sources) {
   4.115 +            new DefaultMethodsNotVisibleForSourceLessThan8Test().run(source);
   4.116 +        }
   4.117 +    }
   4.118 +
   4.119 +    String outDir;
   4.120 +    String source;
   4.121 +
   4.122 +    void run(String source) throws Exception {
   4.123 +        this.source = source;
   4.124 +        outDir = "out" + source.replace('.', '_');
   4.125 +        testsPreparation();
   4.126 +        testLegacyImplementations();
   4.127 +        testLegacyInvocations();
   4.128 +        testSuperInvocations();
   4.129 +    }
   4.130 +
   4.131 +    void testsPreparation() throws Exception {
   4.132 +        Files.createDirectory(Paths.get(outDir));
   4.133 +
   4.134 +        /* as an extra check let's make sure that interface 'I' can't be compiled
   4.135 +         * with source < 8
   4.136 +         */
   4.137 +        ToolBox.JavaToolArgs javacArgs =
   4.138 +                new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)
   4.139 +                .setOptions("-d", outDir, "-source", source)
   4.140 +                .setSources(ISrc);
   4.141 +        ToolBox.javac(javacArgs);
   4.142 +
   4.143 +        //but it should compile with source >= 8
   4.144 +        javacArgs =
   4.145 +                new ToolBox.JavaToolArgs()
   4.146 +                .setOptions("-d", outDir)
   4.147 +                .setSources(ISrc);
   4.148 +        ToolBox.javac(javacArgs);
   4.149 +
   4.150 +        javacArgs =
   4.151 +                new ToolBox.JavaToolArgs()
   4.152 +                .setOptions("-cp", outDir, "-d", outDir, "-source", source)
   4.153 +                .setSources(JSrc, ASrc, BSrc);
   4.154 +        ToolBox.javac(javacArgs);
   4.155 +    }
   4.156 +
   4.157 +    void testLegacyImplementations() throws Exception {
   4.158 +        //compile C1-4
   4.159 +        ToolBox.JavaToolArgs javacArgs =
   4.160 +                new ToolBox.JavaToolArgs()
   4.161 +                .setOptions("-cp", outDir, "-d", outDir, "-source", source)
   4.162 +                .setSources(C1Src, C2Src, C3Src, C4Src);
   4.163 +        ToolBox.javac(javacArgs);
   4.164 +    }
   4.165 +
   4.166 +    void testLegacyInvocations() throws Exception {
   4.167 +        //compile LegacyInvocation
   4.168 +        ToolBox.JavaToolArgs javacArgs =
   4.169 +                new ToolBox.JavaToolArgs()
   4.170 +                .setOptions("-cp", outDir, "-d", outDir, "-source", source)
   4.171 +                .setSources(LegacyInvocationSrc);
   4.172 +        ToolBox.javac(javacArgs);
   4.173 +    }
   4.174 +
   4.175 +    void testSuperInvocations() throws Exception {
   4.176 +        //compile SubA, SubB
   4.177 +        ToolBox.JavaToolArgs javacArgs =
   4.178 +                new ToolBox.JavaToolArgs()
   4.179 +                .setOptions("-cp", outDir, "-d", outDir, "-source", source)
   4.180 +                .setSources(SubASrc, SubBSrc);
   4.181 +        ToolBox.javac(javacArgs);
   4.182 +    }
   4.183 +}

mercurial