提交 6c3e30ee 编写于 作者: L lana

Merge

...@@ -2540,7 +2540,7 @@ public class Lower extends TreeTranslator { ...@@ -2540,7 +2540,7 @@ public class Lower extends TreeTranslator {
currentMethodSym = currentMethodSymPrev; currentMethodSym = currentMethodSymPrev;
// Return empty block {} as a placeholder for an inner class. // Return empty block {} as a placeholder for an inner class.
result = make_at(tree.pos()).Block(0, List.<JCStatement>nil()); result = make_at(tree.pos()).Block(SYNTHETIC, List.<JCStatement>nil());
} }
/** Translate an enum class. */ /** Translate an enum class. */
......
...@@ -836,20 +836,19 @@ public class Resolve { ...@@ -836,20 +836,19 @@ public class Resolve {
List<Type> formals, List<Type> formals,
Warner warn) { Warner warn) {
super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn);
//should we expand formals? // should we check varargs element type accessibility?
if (deferredAttrContext.phase.isVarargsRequired()) { if (deferredAttrContext.phase.isVarargsRequired()) {
Type typeToCheck = null; if (deferredAttrContext.mode == AttrMode.CHECK || !checkVarargsAccessAfterResolution) {
if (!checkVarargsAccessAfterResolution) { varargsAccessible(env, types.elemtype(formals.last()), deferredAttrContext.inferenceContext);
typeToCheck = types.elemtype(formals.last());
} else if (deferredAttrContext.mode == AttrMode.CHECK) {
typeToCheck = types.erasure(types.elemtype(formals.last()));
}
if (typeToCheck != null) {
varargsAccessible(env, typeToCheck, deferredAttrContext.inferenceContext);
} }
} }
} }
/**
* Test that the runtime array element type corresponding to 't' is accessible. 't' should be the
* varargs element type of either the method invocation type signature (after inference completes)
* or the method declaration signature (before inference completes).
*/
private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) {
if (inferenceContext.free(t)) { if (inferenceContext.free(t)) {
inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() {
...@@ -859,7 +858,7 @@ public class Resolve { ...@@ -859,7 +858,7 @@ public class Resolve {
} }
}); });
} else { } else {
if (!isAccessible(env, t)) { if (!isAccessible(env, types.erasure(t))) {
Symbol location = env.enclClass.sym; Symbol location = env.enclClass.sym;
reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location);
} }
......
...@@ -486,7 +486,7 @@ public class Gen extends JCTree.Visitor { ...@@ -486,7 +486,7 @@ public class Gen extends JCTree.Visitor {
JCBlock block = (JCBlock)def; JCBlock block = (JCBlock)def;
if ((block.flags & STATIC) != 0) if ((block.flags & STATIC) != 0)
clinitCode.append(block); clinitCode.append(block);
else else if ((block.flags & SYNTHETIC) == 0)
initCode.append(block); initCode.append(block);
break; break;
case METHODDEF: case METHODDEF:
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8061778
* @summary Wrong LineNumberTable for default constructors
*/
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPoolException;
import com.sun.tools.classfile.Method;
import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.LineNumberTable_attribute;
import com.sun.tools.classfile.LineNumberTable_attribute.Entry;
import java.io.IOException;
public class NestedLineNumberTest {
public static void main(String[] args) throws Exception {
Entry[] lines = findEntries();
if (lines == null || lines.length != 1) {
int found = lines == null ? 0 : lines.length;
error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found));
}
int line = lines[0].line_number;
if (line != 78) {
error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 78, line));
}
}
static Entry[] findEntries() throws IOException, ConstantPoolException {
ClassFile self = ClassFile.read(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class"));
for (Method m : self.methods) {
if ("<init>".equals(m.getName(self.constant_pool))) {
Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code);
for (Attribute at : code_attribute.attributes) {
if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) {
return ((LineNumberTable_attribute)at).line_number_table;
}
}
}
}
return null;
}
static void error(String msg) {
throw new AssertionError(msg);
}
// The default constructor in this class should get only one LineNumberTable entry,
// pointing to the first line of the declaration of class Test.
static class Test {
static class Empty { }
}
}
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Auxiliary file for VarargsInferredPrivateType
*/
package otherpackage;
public class OtherPackage {
public static Private getPrivate() {
return new Private();
}
private static class Private {}
}
\ No newline at end of file
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
* @bug 8049075 * @bug 8049075
* @summary javac, wildcards and generic vararg method invocation not accepted * @summary javac, wildcards and generic vararg method invocation not accepted
* @compile VarargsAndWildcardParameterizedTypeTest.java * @compile VarargsAndWildcardParameterizedTypeTest.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest.java
*/ */
class VarargsAndWildcardParameterizedTypeTest { class VarargsAndWildcardParameterizedTypeTest {
......
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8075520
* @summary Varargs access check mishandles capture variables
* @compile VarargsAndWildcardParameterizedTypeTest2.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest2.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest2.java
*/
class VarargsAndWildcardParameterizedTypeTest2 {
interface I {
<T> void m(T... t);
}
interface Box<T> {
T get();
}
void m(I i, Box<? extends Number> b) {
i.m(b.get());
}
}
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8075520
* @summary Varargs access check mishandles capture variables
* @compile VarargsAndWildcardParameterizedTypeTest3.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest3.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest3.java
*/
class VarargsAndWildcardParameterizedTypeTest2 {
interface I {
<T> void m(Box<? extends T> iter, T... t);
}
interface Box<T> {}
void m(I i, Box<? extends Number> b) {
i.m(b);
}
}
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8075520
* @summary Varargs access check mishandles capture variables
* @compile VarargsAndWildcardParameterizedTypeTest4.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest4.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest4.java
*/
class VarargsAndWildcardParameterizedTypeTest2 {
interface I {
<T> void m(Box<T> iter, T... t);
}
interface Box<T> {}
void m(I i, Box<? extends Number> b) {
i.m(b);
}
}
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)
- compiler.note.unchecked.filename: VarargsInferredPrivateType.java
- compiler.note.unchecked.recompile
1 error
/*
* @test /nodynamiccopyright/
* @bug 8077786
* @summary Check varargs access against inferred signature
* @compile/fail/ref=VarargsInferredPrivateType.out -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java
* @compile/fail/ref=VarargsInferredPrivateType.out -source 8 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java
* @compile/fail/ref=VarargsInferredPrivateType-source7.out -source 7 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java
*/
class VarargsInferredPrivateType {
interface I {
<T> void m(T... t);
}
void m(I i) {
i.m(otherpackage.OtherPackage.getPrivate());
}
}
VarargsInferredPrivateType.java:16:12: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType)
- compiler.note.unchecked.filename: VarargsInferredPrivateType.java
- compiler.note.unchecked.recompile
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册