7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class

Fri, 08 Feb 2013 09:12:37 +0000

author
vromero
date
Fri, 08 Feb 2013 09:12:37 +0000
changeset 1555
762d0af062f5
parent 1554
5125b9854d07
child 1556
b1deb90d2e37

7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Gen.java file | annotate | diff | comparison | revisions
test/tools/javac/7166455/CheckACC_STRICTFlagOnclinitTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 07 20:47:06 2013 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Feb 08 09:12:37 2013 +0000
     1.3 @@ -1099,8 +1099,9 @@
     1.4              Env<AttrContext> localEnv =
     1.5                  env.dup(tree, env.info.dup(env.info.scope.dupUnshared()));
     1.6              localEnv.info.scope.owner =
     1.7 -                new MethodSymbol(tree.flags | BLOCK, names.empty, null,
     1.8 -                                 env.info.scope.owner);
     1.9 +                new MethodSymbol(tree.flags | BLOCK |
    1.10 +                    env.info.scope.owner.flags() & STRICTFP, names.empty, null,
    1.11 +                    env.info.scope.owner);
    1.12              if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++;
    1.13  
    1.14              // Attribute all type annotations in the block
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Feb 07 20:47:06 2013 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Feb 08 09:12:37 2013 +0000
     2.3 @@ -1023,7 +1023,7 @@
     2.4          };
     2.5  
     2.6      /** Check that given modifiers are legal for given symbol and
     2.7 -     *  return modifiers together with any implicit modififiers for that symbol.
     2.8 +     *  return modifiers together with any implicit modifiers for that symbol.
     2.9       *  Warning: we can't use flags() here since this method
    2.10       *  is called during class enter, when flags() would cause a premature
    2.11       *  completion.
    2.12 @@ -1069,7 +1069,7 @@
    2.13              }
    2.14              // Imply STRICTFP if owner has STRICTFP set.
    2.15              if (((flags|implicit) & Flags.ABSTRACT) == 0)
    2.16 -              implicit |= sym.owner.flags_field & STRICTFP;
    2.17 +                implicit |= sym.owner.flags_field & STRICTFP;
    2.18              break;
    2.19          case TYP:
    2.20              if (sym.isLocal()) {
     3.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Thu Feb 07 20:47:06 2013 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Feb 08 09:12:37 2013 +0000
     3.3 @@ -513,7 +513,8 @@
     3.4          // that contains them as its body.
     3.5          if (clinitCode.length() != 0) {
     3.6              MethodSymbol clinit = new MethodSymbol(
     3.7 -                STATIC, names.clinit,
     3.8 +                STATIC | (c.flags() & STRICTFP),
     3.9 +                names.clinit,
    3.10                  new MethodType(
    3.11                      List.<Type>nil(), syms.voidType,
    3.12                      List.<Type>nil(), syms.methodClass),
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/7166455/CheckACC_STRICTFlagOnclinitTest.java	Fri Feb 08 09:12:37 2013 +0000
     4.3 @@ -0,0 +1,107 @@
     4.4 +/*
     4.5 + * Copyright (c) 2013, 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 7166455
    4.32 + * @summary javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
    4.33 + * @run main CheckACC_STRICTFlagOnclinitTest
    4.34 + */
    4.35 +
    4.36 +import java.util.ArrayList;
    4.37 +import java.util.List;
    4.38 +import java.io.File;
    4.39 +import java.io.IOException;
    4.40 +import com.sun.tools.classfile.ClassFile;
    4.41 +import com.sun.tools.classfile.ConstantPoolException;
    4.42 +import com.sun.tools.classfile.Descriptor;
    4.43 +import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
    4.44 +import com.sun.tools.classfile.Method;
    4.45 +
    4.46 +import static com.sun.tools.classfile.AccessFlags.ACC_STRICT;
    4.47 +
    4.48 +public strictfp class CheckACC_STRICTFlagOnclinitTest {
    4.49 +    private static final String AssertionErrorMessage =
    4.50 +        "All methods should have the ACC_STRICT access flag " +
    4.51 +        "please check output";
    4.52 +    private static final String offendingMethodErrorMessage =
    4.53 +        "Method %s of class %s doesn't have the ACC_STRICT access flag";
    4.54 +
    4.55 +    static {
    4.56 +        class Foo {
    4.57 +            class Bar {
    4.58 +                void m11() {}
    4.59 +            }
    4.60 +            void m1() {}
    4.61 +        }
    4.62 +    }
    4.63 +    void m2() {
    4.64 +        class Any {
    4.65 +            void m21() {}
    4.66 +        }
    4.67 +    }
    4.68 +
    4.69 +    private List<String> errors = new ArrayList<>();
    4.70 +
    4.71 +    public static void main(String[] args)
    4.72 +            throws IOException, ConstantPoolException, InvalidDescriptor {
    4.73 +        new CheckACC_STRICTFlagOnclinitTest().run();
    4.74 +    }
    4.75 +
    4.76 +    private void run()
    4.77 +            throws IOException, ConstantPoolException, InvalidDescriptor {
    4.78 +        String testClasses = System.getProperty("test.classes");
    4.79 +        check(testClasses,
    4.80 +              "CheckACC_STRICTFlagOnclinitTest.class",
    4.81 +              "CheckACC_STRICTFlagOnclinitTest$1Foo.class",
    4.82 +              "CheckACC_STRICTFlagOnclinitTest$1Foo$Bar.class",
    4.83 +              "CheckACC_STRICTFlagOnclinitTest$1Any.class");
    4.84 +        if (errors.size() > 0) {
    4.85 +            for (String error: errors) {
    4.86 +                System.err.println(error);
    4.87 +            }
    4.88 +            throw new AssertionError(AssertionErrorMessage);
    4.89 +        }
    4.90 +    }
    4.91 +
    4.92 +    void check(String dir, String... fileNames)
    4.93 +        throws
    4.94 +            IOException,
    4.95 +            ConstantPoolException,
    4.96 +            Descriptor.InvalidDescriptor {
    4.97 +        for (String fileName : fileNames) {
    4.98 +            ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));
    4.99 +
   4.100 +            for (Method method : classFileToCheck.methods) {
   4.101 +                if ((method.access_flags.flags & ACC_STRICT) == 0) {
   4.102 +                    errors.add(String.format(offendingMethodErrorMessage,
   4.103 +                            method.getName(classFileToCheck.constant_pool),
   4.104 +                            classFileToCheck.getName()));
   4.105 +                }
   4.106 +            }
   4.107 +        }
   4.108 +    }
   4.109 +
   4.110 +}

mercurial