langtools/test/tools/javac/defaultMethods/CheckACC_STRICTFlagOnDefaultMethodTest.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 17281 7c38e715fd75
child 30846 2b3f379840f0
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17281
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 17281
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
17281
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     4
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    10
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    15
 * accompanied this code).
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    16
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    20
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    23
 * questions.
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    24
 */
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    25
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    26
/*
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    27
 * @test
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    28
 * @bug 8012723
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    29
 * @summary strictfp interface misses strictfp modifer on default method
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 17281
diff changeset
    30
 * @modules jdk.compiler/com.sun.tools.classfile
17281
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    31
 * @run main CheckACC_STRICTFlagOnDefaultMethodTest
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    32
 */
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    33
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    34
import java.util.ArrayList;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    35
import java.util.List;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    36
import java.io.File;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    37
import java.io.IOException;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    38
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    39
import com.sun.tools.classfile.ClassFile;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    40
import com.sun.tools.classfile.ConstantPoolException;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    41
import com.sun.tools.classfile.Descriptor;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    42
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    43
import com.sun.tools.classfile.Method;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    44
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    45
import static com.sun.tools.classfile.AccessFlags.ACC_STRICT;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    46
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    47
public class CheckACC_STRICTFlagOnDefaultMethodTest {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    48
    private static final String AssertionErrorMessage =
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    49
        "All methods should have the ACC_STRICT access flag " +
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    50
        "please check output";
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    51
    private static final String offendingMethodErrorMessage =
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    52
        "Method %s of class %s doesn't have the ACC_STRICT access flag";
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    53
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    54
    private List<String> errors = new ArrayList<>();
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    55
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    56
    public static void main(String[] args)
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    57
            throws IOException, ConstantPoolException, InvalidDescriptor {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    58
        new CheckACC_STRICTFlagOnDefaultMethodTest().run();
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    59
    }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    60
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    61
    private void run()
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    62
            throws IOException, ConstantPoolException, InvalidDescriptor {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    63
        String testClasses = System.getProperty("test.classes");
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    64
        check(testClasses,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    65
                "CheckACC_STRICTFlagOnDefaultMethodTest$StrictfpInterface.class");
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    66
        if (errors.size() > 0) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    67
            for (String error: errors) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    68
                System.err.println(error);
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    69
            }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    70
            throw new AssertionError(AssertionErrorMessage);
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    71
        }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    72
    }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    73
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    74
    void check(String dir, String... fileNames)
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    75
        throws
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    76
            IOException,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    77
            ConstantPoolException,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    78
            Descriptor.InvalidDescriptor {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    79
        for (String fileName : fileNames) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    80
            ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    81
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    82
            for (Method method : classFileToCheck.methods) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    83
                if ((method.access_flags.flags & ACC_STRICT) == 0) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    84
                    errors.add(String.format(offendingMethodErrorMessage,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    85
                            method.getName(classFileToCheck.constant_pool),
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    86
                            classFileToCheck.getName()));
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    87
                }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    88
            }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    89
        }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    90
    }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    91
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    92
    strictfp interface StrictfpInterface {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    93
        default void default_interface_method() {}
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    94
        static void static_interface_method() {}
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    95
    }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    96
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    97
}