Wed, 29 Apr 2015 14:05:27 -0700
Merge
test/tools/javac/varargs/T8049075/VarargsAndWildcardParameterizedTypeTest.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Apr 29 12:16:42 2015 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Apr 29 14:05:27 2015 -0700 1.3 @@ -2540,7 +2540,7 @@ 1.4 currentMethodSym = currentMethodSymPrev; 1.5 1.6 // Return empty block {} as a placeholder for an inner class. 1.7 - result = make_at(tree.pos()).Block(0, List.<JCStatement>nil()); 1.8 + result = make_at(tree.pos()).Block(SYNTHETIC, List.<JCStatement>nil()); 1.9 } 1.10 1.11 /** Translate an enum class. */
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Apr 29 12:16:42 2015 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Apr 29 14:05:27 2015 -0700 2.3 @@ -836,20 +836,19 @@ 2.4 List<Type> formals, 2.5 Warner warn) { 2.6 super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); 2.7 - //should we expand formals? 2.8 + // should we check varargs element type accessibility? 2.9 if (deferredAttrContext.phase.isVarargsRequired()) { 2.10 - Type typeToCheck = null; 2.11 - if (!checkVarargsAccessAfterResolution) { 2.12 - typeToCheck = types.elemtype(formals.last()); 2.13 - } else if (deferredAttrContext.mode == AttrMode.CHECK) { 2.14 - typeToCheck = types.erasure(types.elemtype(formals.last())); 2.15 - } 2.16 - if (typeToCheck != null) { 2.17 - varargsAccessible(env, typeToCheck, deferredAttrContext.inferenceContext); 2.18 + if (deferredAttrContext.mode == AttrMode.CHECK || !checkVarargsAccessAfterResolution) { 2.19 + varargsAccessible(env, types.elemtype(formals.last()), deferredAttrContext.inferenceContext); 2.20 } 2.21 } 2.22 } 2.23 2.24 + /** 2.25 + * Test that the runtime array element type corresponding to 't' is accessible. 't' should be the 2.26 + * varargs element type of either the method invocation type signature (after inference completes) 2.27 + * or the method declaration signature (before inference completes). 2.28 + */ 2.29 private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { 2.30 if (inferenceContext.free(t)) { 2.31 inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { 2.32 @@ -859,7 +858,7 @@ 2.33 } 2.34 }); 2.35 } else { 2.36 - if (!isAccessible(env, t)) { 2.37 + if (!isAccessible(env, types.erasure(t))) { 2.38 Symbol location = env.enclClass.sym; 2.39 reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); 2.40 }
3.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Apr 29 12:16:42 2015 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Apr 29 14:05:27 2015 -0700 3.3 @@ -486,7 +486,7 @@ 3.4 JCBlock block = (JCBlock)def; 3.5 if ((block.flags & STATIC) != 0) 3.6 clinitCode.append(block); 3.7 - else 3.8 + else if ((block.flags & SYNTHETIC) == 0) 3.9 initCode.append(block); 3.10 break; 3.11 case METHODDEF:
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/linenumbers/NestedLineNumberTest.java Wed Apr 29 14:05:27 2015 -0700 4.3 @@ -0,0 +1,81 @@ 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. Oracle designates this 4.11 + * particular file as subject to the "Classpath" exception as provided 4.12 + * by Oracle in the LICENSE file that accompanied this code. 4.13 + * 4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.17 + * version 2 for more details (a copy is included in the LICENSE file that 4.18 + * accompanied this code). 4.19 + * 4.20 + * You should have received a copy of the GNU General Public License version 4.21 + * 2 along with this work; if not, write to the Free Software Foundation, 4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.23 + * 4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.25 + * or visit www.oracle.com if you need additional information or have any 4.26 + * questions. 4.27 + */ 4.28 + 4.29 +/* 4.30 + * @test 4.31 + * @bug 8061778 4.32 + * @summary Wrong LineNumberTable for default constructors 4.33 + */ 4.34 + 4.35 +import com.sun.tools.classfile.ClassFile; 4.36 +import com.sun.tools.classfile.ConstantPoolException; 4.37 +import com.sun.tools.classfile.Method; 4.38 +import com.sun.tools.classfile.Attribute; 4.39 +import com.sun.tools.classfile.Code_attribute; 4.40 +import com.sun.tools.classfile.LineNumberTable_attribute; 4.41 +import com.sun.tools.classfile.LineNumberTable_attribute.Entry; 4.42 + 4.43 +import java.io.IOException; 4.44 + 4.45 +public class NestedLineNumberTest { 4.46 + 4.47 + public static void main(String[] args) throws Exception { 4.48 + Entry[] lines = findEntries(); 4.49 + if (lines == null || lines.length != 1) { 4.50 + int found = lines == null ? 0 : lines.length; 4.51 + error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found)); 4.52 + } 4.53 + 4.54 + int line = lines[0].line_number; 4.55 + if (line != 78) { 4.56 + error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 78, line)); 4.57 + } 4.58 + } 4.59 + 4.60 + static Entry[] findEntries() throws IOException, ConstantPoolException { 4.61 + ClassFile self = ClassFile.read(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class")); 4.62 + for (Method m : self.methods) { 4.63 + if ("<init>".equals(m.getName(self.constant_pool))) { 4.64 + Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code); 4.65 + for (Attribute at : code_attribute.attributes) { 4.66 + if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) { 4.67 + return ((LineNumberTable_attribute)at).line_number_table; 4.68 + } 4.69 + } 4.70 + } 4.71 + } 4.72 + return null; 4.73 + } 4.74 + 4.75 + static void error(String msg) { 4.76 + throw new AssertionError(msg); 4.77 + } 4.78 + 4.79 + // The default constructor in this class should get only one LineNumberTable entry, 4.80 + // pointing to the first line of the declaration of class Test. 4.81 + static class Test { 4.82 + static class Empty { } 4.83 + } 4.84 +}
5.1 --- a/test/tools/javac/varargs/T8049075/VarargsAndWildcardParameterizedTypeTest.java Wed Apr 29 12:16:42 2015 -0700 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,40 +0,0 @@ 5.4 -/* 5.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 - * 5.8 - * This code is free software; you can redistribute it and/or modify it 5.9 - * under the terms of the GNU General Public License version 2 only, as 5.10 - * published by the Free Software Foundation. 5.11 - * 5.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 - * version 2 for more details (a copy is included in the LICENSE file that 5.16 - * accompanied this code). 5.17 - * 5.18 - * You should have received a copy of the GNU General Public License version 5.19 - * 2 along with this work; if not, write to the Free Software Foundation, 5.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 - * 5.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 - * or visit www.oracle.com if you need additional information or have any 5.24 - * questions. 5.25 - */ 5.26 - 5.27 -/* 5.28 - * @test 5.29 - * @bug 8049075 5.30 - * @summary javac, wildcards and generic vararg method invocation not accepted 5.31 - * @compile VarargsAndWildcardParameterizedTypeTest.java 5.32 - */ 5.33 - 5.34 -class VarargsAndWildcardParameterizedTypeTest { 5.35 - interface I<T> { 5.36 - String m(T... t); 5.37 - } 5.38 - 5.39 - void m() { 5.40 - I<? super Integer> i = null; 5.41 - i.m(Integer.valueOf(1), Integer.valueOf(1)); 5.42 - } 5.43 -}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/varargs/access/OtherPackage.java Wed Apr 29 14:05:27 2015 -0700 6.3 @@ -0,0 +1,36 @@ 6.4 +/* 6.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/* 6.28 + * Auxiliary file for VarargsInferredPrivateType 6.29 + */ 6.30 + 6.31 +package otherpackage; 6.32 + 6.33 +public class OtherPackage { 6.34 + public static Private getPrivate() { 6.35 + return new Private(); 6.36 + } 6.37 + 6.38 + private static class Private {} 6.39 +} 6.40 \ No newline at end of file
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest.java Wed Apr 29 14:05:27 2015 -0700 7.3 @@ -0,0 +1,42 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +/* 7.28 + * @test 7.29 + * @bug 8049075 7.30 + * @summary javac, wildcards and generic vararg method invocation not accepted 7.31 + * @compile VarargsAndWildcardParameterizedTypeTest.java 7.32 + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest.java 7.33 + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest.java 7.34 + */ 7.35 + 7.36 +class VarargsAndWildcardParameterizedTypeTest { 7.37 + interface I<T> { 7.38 + String m(T... t); 7.39 + } 7.40 + 7.41 + void m() { 7.42 + I<? super Integer> i = null; 7.43 + i.m(Integer.valueOf(1), Integer.valueOf(1)); 7.44 + } 7.45 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest2.java Wed Apr 29 14:05:27 2015 -0700 8.3 @@ -0,0 +1,45 @@ 8.4 +/* 8.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +/* 8.28 + * @test 8.29 + * @bug 8075520 8.30 + * @summary Varargs access check mishandles capture variables 8.31 + * @compile VarargsAndWildcardParameterizedTypeTest2.java 8.32 + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest2.java 8.33 + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest2.java 8.34 + */ 8.35 + 8.36 +class VarargsAndWildcardParameterizedTypeTest2 { 8.37 + interface I { 8.38 + <T> void m(T... t); 8.39 + } 8.40 + 8.41 + interface Box<T> { 8.42 + T get(); 8.43 + } 8.44 + 8.45 + void m(I i, Box<? extends Number> b) { 8.46 + i.m(b.get()); 8.47 + } 8.48 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest3.java Wed Apr 29 14:05:27 2015 -0700 9.3 @@ -0,0 +1,43 @@ 9.4 +/* 9.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/* 9.28 + * @test 9.29 + * @bug 8075520 9.30 + * @summary Varargs access check mishandles capture variables 9.31 + * @compile VarargsAndWildcardParameterizedTypeTest3.java 9.32 + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest3.java 9.33 + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest3.java 9.34 + */ 9.35 + 9.36 +class VarargsAndWildcardParameterizedTypeTest2 { 9.37 + interface I { 9.38 + <T> void m(Box<? extends T> iter, T... t); 9.39 + } 9.40 + 9.41 + interface Box<T> {} 9.42 + 9.43 + void m(I i, Box<? extends Number> b) { 9.44 + i.m(b); 9.45 + } 9.46 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest4.java Wed Apr 29 14:05:27 2015 -0700 10.3 @@ -0,0 +1,43 @@ 10.4 +/* 10.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.23 + * or visit www.oracle.com if you need additional information or have any 10.24 + * questions. 10.25 + */ 10.26 + 10.27 +/* 10.28 + * @test 10.29 + * @bug 8075520 10.30 + * @summary Varargs access check mishandles capture variables 10.31 + * @compile VarargsAndWildcardParameterizedTypeTest4.java 10.32 + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest4.java 10.33 + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest4.java 10.34 + */ 10.35 + 10.36 +class VarargsAndWildcardParameterizedTypeTest2 { 10.37 + interface I { 10.38 + <T> void m(Box<T> iter, T... t); 10.39 + } 10.40 + 10.41 + interface Box<T> {} 10.42 + 10.43 + void m(I i, Box<? extends Number> b) { 10.44 + i.m(b); 10.45 + } 10.46 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/varargs/access/VarargsInferredPrivateType-source7.out Wed Apr 29 14:05:27 2015 -0700 11.3 @@ -0,0 +1,4 @@ 11.4 +VarargsInferredPrivateType.java:16:10: compiler.err.cant.apply.symbol: kindname.method, m, T[], otherpackage.OtherPackage.Private, kindname.interface, VarargsInferredPrivateType.I, (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType) 11.5 +- compiler.note.unchecked.filename: VarargsInferredPrivateType.java 11.6 +- compiler.note.unchecked.recompile 11.7 +1 error
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/varargs/access/VarargsInferredPrivateType.java Wed Apr 29 14:05:27 2015 -0700 12.3 @@ -0,0 +1,18 @@ 12.4 +/* 12.5 + * @test /nodynamiccopyright/ 12.6 + * @bug 8077786 12.7 + * @summary Check varargs access against inferred signature 12.8 + * @compile/fail/ref=VarargsInferredPrivateType.out -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java 12.9 + * @compile/fail/ref=VarargsInferredPrivateType.out -source 8 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java 12.10 + * @compile/fail/ref=VarargsInferredPrivateType-source7.out -source 7 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java 12.11 + */ 12.12 + 12.13 +class VarargsInferredPrivateType { 12.14 + interface I { 12.15 + <T> void m(T... t); 12.16 + } 12.17 + 12.18 + void m(I i) { 12.19 + i.m(otherpackage.OtherPackage.getPrivate()); 12.20 + } 12.21 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/varargs/access/VarargsInferredPrivateType.out Wed Apr 29 14:05:27 2015 -0700 13.3 @@ -0,0 +1,4 @@ 13.4 +VarargsInferredPrivateType.java:16:12: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType) 13.5 +- compiler.note.unchecked.filename: VarargsInferredPrivateType.java 13.6 +- compiler.note.unchecked.recompile 13.7 +1 error