Fri, 30 May 2014 18:21:05 +0100
8042785: javac, bridge methods are not getting the flags from the original method
Reviewed-by: jjg, jlahoda
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Tue May 27 22:26:53 2014 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Fri May 30 18:21:05 2014 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -294,8 +294,8 @@ 1.11 ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT, 1.12 InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT, 1.13 AnnotationTypeElementMask = ABSTRACT | PUBLIC, 1.14 - LocalVarFlags = FINAL | PARAMETER; 1.15 - 1.16 + LocalVarFlags = FINAL | PARAMETER, 1.17 + BridgeMethodMask = AccessFlags | FINAL | STRICTFP; 1.18 1.19 public static Set<Modifier> asModifierSet(long flags) { 1.20 Set<Modifier> modifiers = modifierSets.get(flags);
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Tue May 27 22:26:53 2014 +0100 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Fri May 30 18:21:05 2014 +0100 2.3 @@ -254,7 +254,7 @@ 2.4 2.5 // Create a bridge method symbol and a bridge definition without a body. 2.6 Type bridgeType = meth.erasure(types); 2.7 - long flags = impl.flags() & AccessFlags | SYNTHETIC | BRIDGE | 2.8 + long flags = impl.flags() & BridgeMethodMask | SYNTHETIC | BRIDGE | 2.9 (origin.isInterface() ? DEFAULT : 0); 2.10 if (hypothetical) flags |= HYPOTHETICAL; 2.11 MethodSymbol bridge = new MethodSymbol(flags, 2.12 @@ -932,7 +932,7 @@ 2.13 ClassSymbol c, 2.14 ListBuffer<JCTree> bridges) { 2.15 Type implErasure = impl.erasure(types); 2.16 - long flags = (impl.flags() & AccessFlags) | SYNTHETIC | BRIDGE | OVERRIDE_BRIDGE; 2.17 + long flags = impl.flags() & BridgeMethodMask | SYNTHETIC | BRIDGE | OVERRIDE_BRIDGE; 2.18 member = new MethodSymbol(flags, member.name, member.type, c); 2.19 JCMethodDecl md = make.MethodDef(member, null); 2.20 JCExpression receiver = make.Super(types.supertype(c.type).tsym.erasure(types), c);
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/T8042785/FlagsNotCopiedToBridgeMethodTest.java Fri May 30 18:21:05 2014 +0100 3.3 @@ -0,0 +1,79 @@ 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 8042785 3.30 + * @summary javac, bridge methods are not getting the flags from the original method 3.31 + * @run main FlagsNotCopiedToBridgeMethodTest 3.32 + */ 3.33 + 3.34 +import java.io.BufferedInputStream; 3.35 +import java.nio.file.Files; 3.36 +import java.nio.file.Path; 3.37 +import java.nio.file.Paths; 3.38 + 3.39 +import com.sun.tools.classfile.AccessFlags; 3.40 +import com.sun.tools.classfile.ClassFile; 3.41 +import com.sun.tools.classfile.Method; 3.42 +import com.sun.tools.javac.util.Assert; 3.43 + 3.44 +public class FlagsNotCopiedToBridgeMethodTest { 3.45 + 3.46 + public static void main(String[] args) throws Exception { 3.47 + new FlagsNotCopiedToBridgeMethodTest().run(); 3.48 + } 3.49 + 3.50 + void run() throws Exception { 3.51 + checkClassFile(Paths.get(System.getProperty("test.classes"), 3.52 + this.getClass().getSimpleName() + "$CovariantReturnType.class")); 3.53 + checkClassFile(Paths.get(System.getProperty("test.classes"), 3.54 + this.getClass().getSimpleName() + 3.55 + "$CovariantReturnType$VisibilityChange.class")); 3.56 + } 3.57 + 3.58 + void checkClassFile(final Path cfilePath) throws Exception { 3.59 + ClassFile classFile = ClassFile.read( 3.60 + new BufferedInputStream(Files.newInputStream(cfilePath))); 3.61 + for (Method method : classFile.methods) { 3.62 + if (method.access_flags.is(AccessFlags.ACC_BRIDGE)) { 3.63 + Assert.check(method.access_flags.is(AccessFlags.ACC_FINAL | AccessFlags.ACC_STRICT), 3.64 + "bridge method has incorrect flags"); 3.65 + } 3.66 + } 3.67 + } 3.68 + 3.69 + abstract class T<A,B> { 3.70 + B m(A a){ return null; } 3.71 + } 3.72 + 3.73 + class CovariantReturnType extends T<Integer, Integer> { 3.74 + strictfp final Integer m(Integer i) { 3.75 + return i; 3.76 + } 3.77 + 3.78 + public class VisibilityChange extends CovariantReturnType {} 3.79 + 3.80 + } 3.81 + 3.82 +}