hotspot/test/runtime/classFileParserBug/TestEmptyBootstrapMethodsAttr.java
author jjg
Fri, 07 Nov 2014 14:51:35 -0800
changeset 27547 d07b3dcbc707
parent 24454 19b3c54faec3
child 29678 dd2f3932c21e
permissions -rw-r--r--
8063145: ToolBox should support extracting classes from a JavaFileManager/Location Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     1
/*
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    29
 * @compile TestEmptyBootstrapMethodsAttr.java
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    30
 * @run main TestEmptyBootstrapMethodsAttr
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    31
 */
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    32
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    33
import java.io.File;
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    34
import com.oracle.java.testlibrary.*;
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    35
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    36
public class TestEmptyBootstrapMethodsAttr {
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 static void main(String args[]) throws Throwable {
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    39
        System.out.println("Regression test for bug 8041918");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    40
        String jarFile = System.getProperty("test.src") + File.separator + "emptynumbootstrapmethods.jar";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    41
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    42
        // ====== extract the test case
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    43
        ProcessBuilder pb = new ProcessBuilder(new String[] { JDKToolFinder.getJDKTool("jar"), "xvf", jarFile } );
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    44
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    45
        output.shouldHaveExitValue(0);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    46
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    47
        // Test case #1:
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    48
        // Try loading class with empty bootstrap_methods table where no
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    49
        // other attributes are following BootstrapMethods in attribute table.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    50
        String className = "emptynumbootstrapmethods1";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    51
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    52
        // ======= execute test case #1
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    53
        // Expect a lack of main method, this implies that the class loaded correctly
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    54
        // with an empty bootstrap_methods and did not generate a ClassFormatError.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    55
        pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    56
        output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    57
        output.shouldNotContain("java.lang.ClassFormatError");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    58
        output.shouldContain("Main method not found in class " + className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    59
        output.shouldHaveExitValue(1);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    60
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    61
        // Test case #2:
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    62
        // Try loading class with empty bootstrap_methods table where an
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    63
        // AnnotationDefault attribute follows the BootstrapMethods in the attribute table.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    64
        className = "emptynumbootstrapmethods2";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    65
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    66
        // ======= execute test case #2
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    67
        // Expect a lack of main method, this implies that the class loaded correctly
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    68
        // with an empty bootstrap_methods and did not generate ClassFormatError.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    69
        pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    70
        output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    71
        output.shouldNotContain("java.lang.ClassFormatError");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    72
        output.shouldContain("Main method not found in class " + className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    73
        output.shouldHaveExitValue(1);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    74
    }
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    75
}