langtools/test/tools/javac/defaultMethods/CheckACC_STRICTFlagOnDefaultMethodTest.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 30846 2b3f379840f0
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
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
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 30846
diff changeset
     7
 * published by the Free Software Foundation.
17281
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     8
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
     9
 * 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
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    11
 * 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
    12
 * 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
    13
 * accompanied this code).
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    14
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    19
 * 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
    20
 * 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
    21
 * questions.
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    22
 */
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    23
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
 * @test
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    26
 * @bug 8012723
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    27
 * @summary strictfp interface misses strictfp modifer on default method
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.classfile
17281
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    29
 * @run main CheckACC_STRICTFlagOnDefaultMethodTest
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    30
 */
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    31
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    32
import java.util.ArrayList;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    33
import java.util.List;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    34
import java.io.File;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    35
import java.io.IOException;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    36
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    37
import com.sun.tools.classfile.ClassFile;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    38
import com.sun.tools.classfile.ConstantPoolException;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    39
import com.sun.tools.classfile.Descriptor;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    40
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    41
import com.sun.tools.classfile.Method;
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    42
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    43
import static com.sun.tools.classfile.AccessFlags.ACC_STRICT;
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
public class CheckACC_STRICTFlagOnDefaultMethodTest {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    46
    private static final String AssertionErrorMessage =
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    47
        "All methods should have the ACC_STRICT access flag " +
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    48
        "please check output";
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    49
    private static final String offendingMethodErrorMessage =
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    50
        "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
    51
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    52
    private List<String> errors = new ArrayList<>();
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
    public static void main(String[] args)
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    55
            throws IOException, ConstantPoolException, InvalidDescriptor {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    56
        new CheckACC_STRICTFlagOnDefaultMethodTest().run();
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    57
    }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    58
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    59
    private void run()
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    60
            throws IOException, ConstantPoolException, InvalidDescriptor {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    61
        String testClasses = System.getProperty("test.classes");
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    62
        check(testClasses,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    63
                "CheckACC_STRICTFlagOnDefaultMethodTest$StrictfpInterface.class");
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    64
        if (errors.size() > 0) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    65
            for (String error: errors) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    66
                System.err.println(error);
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    67
            }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    68
            throw new AssertionError(AssertionErrorMessage);
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
    }
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
    void check(String dir, String... fileNames)
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    73
        throws
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    74
            IOException,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    75
            ConstantPoolException,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    76
            Descriptor.InvalidDescriptor {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    77
        for (String fileName : fileNames) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    78
            ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    79
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    80
            for (Method method : classFileToCheck.methods) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    81
                if ((method.access_flags.flags & ACC_STRICT) == 0) {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    82
                    errors.add(String.format(offendingMethodErrorMessage,
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    83
                            method.getName(classFileToCheck.constant_pool),
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    84
                            classFileToCheck.getName()));
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    85
                }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    86
            }
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
    strictfp interface StrictfpInterface {
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    91
        default void default_interface_method() {}
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    92
        static void static_interface_method() {}
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    93
    }
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    94
7c38e715fd75 8012723: strictfp interface misses strictfp modifer on default method
vromero
parents:
diff changeset
    95
}