hotspot/test/runtime/classFileParserBug/TestEmptyBootstrapMethodsAttr.java
author jprovino
Wed, 11 Nov 2015 23:47:42 +0000
changeset 33911 af2cff5bd523
parent 30604 b8d532cb6420
child 36851 03e2f4d0a421
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 24454
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     4
 *
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     8
 *
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    13
 * accompanied this code).
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    14
 *
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    18
 *
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    21
 * questions.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    22
 */
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    23
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    24
/*
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    25
 * @test TestEmptyBootstrapMethodsAttr
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    26
 * @bug 8041918
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    27
 * @library /testlibrary
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    28
 * @summary Test empty bootstrap_methods table within BootstrapMethods attribute
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 24454
diff changeset
    29
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 24454
diff changeset
    30
 *          java.management
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    31
 * @compile TestEmptyBootstrapMethodsAttr.java
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    32
 * @run main TestEmptyBootstrapMethodsAttr
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    33
 */
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    34
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    35
import java.io.File;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    36
import jdk.test.lib.*;
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    37
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    38
public class TestEmptyBootstrapMethodsAttr {
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    39
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    40
    public static void main(String args[]) throws Throwable {
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    41
        System.out.println("Regression test for bug 8041918");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    42
        String jarFile = System.getProperty("test.src") + File.separator + "emptynumbootstrapmethods.jar";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    43
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    44
        // ====== extract the test case
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    45
        ProcessBuilder pb = new ProcessBuilder(new String[] { JDKToolFinder.getJDKTool("jar"), "xvf", jarFile } );
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    46
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    47
        output.shouldHaveExitValue(0);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    48
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    49
        // Test case #1:
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    50
        // Try loading class with empty bootstrap_methods table where no
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    51
        // other attributes are following BootstrapMethods in attribute table.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    52
        String className = "emptynumbootstrapmethods1";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    53
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    54
        // ======= execute test case #1
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    55
        // Expect a lack of main method, this implies that the class loaded correctly
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    56
        // with an empty bootstrap_methods and did not generate a ClassFormatError.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    57
        pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    58
        output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    59
        output.shouldNotContain("java.lang.ClassFormatError");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    60
        output.shouldContain("Main method not found in class " + className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    61
        output.shouldHaveExitValue(1);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    62
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    63
        // Test case #2:
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    64
        // Try loading class with empty bootstrap_methods table where an
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    65
        // AnnotationDefault attribute follows the BootstrapMethods in the attribute table.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    66
        className = "emptynumbootstrapmethods2";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    67
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    68
        // ======= execute test case #2
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    69
        // Expect a lack of main method, this implies that the class loaded correctly
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    70
        // with an empty bootstrap_methods and did not generate ClassFormatError.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    71
        pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    72
        output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    73
        output.shouldNotContain("java.lang.ClassFormatError");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    74
        output.shouldContain("Main method not found in class " + className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    75
        output.shouldHaveExitValue(1);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    76
    }
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    77
}