8012723: strictfp interface misses strictfp modifer on default method

Fri, 26 Apr 2013 10:04:01 +0100

author
vromero
date
Fri, 26 Apr 2013 10:04:01 +0100
changeset 1712
3c02d2f1a421
parent 1711
4b0038f66d66
child 1713
2ca9e7d50136

8012723: strictfp interface misses strictfp modifer on default method
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/defaultMethods/CheckACC_STRICTFlagOnDefaultMethodTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Apr 25 17:45:36 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Apr 26 10:04:01 2013 +0100
     1.3 @@ -1078,7 +1078,8 @@
     1.4                  mask = MethodFlags;
     1.5              }
     1.6              // Imply STRICTFP if owner has STRICTFP set.
     1.7 -            if (((flags|implicit) & Flags.ABSTRACT) == 0)
     1.8 +            if (((flags|implicit) & Flags.ABSTRACT) == 0 ||
     1.9 +                ((flags) & Flags.DEFAULT) != 0)
    1.10                  implicit |= sym.owner.flags_field & STRICTFP;
    1.11              break;
    1.12          case TYP:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/defaultMethods/CheckACC_STRICTFlagOnDefaultMethodTest.java	Fri Apr 26 10:04:01 2013 +0100
     2.3 @@ -0,0 +1,96 @@
     2.4 +/*
     2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Oracle designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Oracle in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 + * or visit www.oracle.com if you need additional information or have any
    2.26 + * questions.
    2.27 + */
    2.28 +
    2.29 +/*
    2.30 + * @test
    2.31 + * @bug 8012723
    2.32 + * @summary strictfp interface misses strictfp modifer on default method
    2.33 + * @run main CheckACC_STRICTFlagOnDefaultMethodTest
    2.34 + */
    2.35 +
    2.36 +import java.util.ArrayList;
    2.37 +import java.util.List;
    2.38 +import java.io.File;
    2.39 +import java.io.IOException;
    2.40 +
    2.41 +import com.sun.tools.classfile.ClassFile;
    2.42 +import com.sun.tools.classfile.ConstantPoolException;
    2.43 +import com.sun.tools.classfile.Descriptor;
    2.44 +import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
    2.45 +import com.sun.tools.classfile.Method;
    2.46 +
    2.47 +import static com.sun.tools.classfile.AccessFlags.ACC_STRICT;
    2.48 +
    2.49 +public class CheckACC_STRICTFlagOnDefaultMethodTest {
    2.50 +    private static final String AssertionErrorMessage =
    2.51 +        "All methods should have the ACC_STRICT access flag " +
    2.52 +        "please check output";
    2.53 +    private static final String offendingMethodErrorMessage =
    2.54 +        "Method %s of class %s doesn't have the ACC_STRICT access flag";
    2.55 +
    2.56 +    private List<String> errors = new ArrayList<>();
    2.57 +
    2.58 +    public static void main(String[] args)
    2.59 +            throws IOException, ConstantPoolException, InvalidDescriptor {
    2.60 +        new CheckACC_STRICTFlagOnDefaultMethodTest().run();
    2.61 +    }
    2.62 +
    2.63 +    private void run()
    2.64 +            throws IOException, ConstantPoolException, InvalidDescriptor {
    2.65 +        String testClasses = System.getProperty("test.classes");
    2.66 +        check(testClasses,
    2.67 +                "CheckACC_STRICTFlagOnDefaultMethodTest$StrictfpInterface.class");
    2.68 +        if (errors.size() > 0) {
    2.69 +            for (String error: errors) {
    2.70 +                System.err.println(error);
    2.71 +            }
    2.72 +            throw new AssertionError(AssertionErrorMessage);
    2.73 +        }
    2.74 +    }
    2.75 +
    2.76 +    void check(String dir, String... fileNames)
    2.77 +        throws
    2.78 +            IOException,
    2.79 +            ConstantPoolException,
    2.80 +            Descriptor.InvalidDescriptor {
    2.81 +        for (String fileName : fileNames) {
    2.82 +            ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));
    2.83 +
    2.84 +            for (Method method : classFileToCheck.methods) {
    2.85 +                if ((method.access_flags.flags & ACC_STRICT) == 0) {
    2.86 +                    errors.add(String.format(offendingMethodErrorMessage,
    2.87 +                            method.getName(classFileToCheck.constant_pool),
    2.88 +                            classFileToCheck.getName()));
    2.89 +                }
    2.90 +            }
    2.91 +        }
    2.92 +    }
    2.93 +
    2.94 +    strictfp interface StrictfpInterface {
    2.95 +        default void default_interface_method() {}
    2.96 +        static void static_interface_method() {}
    2.97 +    }
    2.98 +
    2.99 +}

mercurial