test/hotspot/jtreg/runtime/classFileParserBug/TestEmptyBootstrapMethodsAttr.java
author iignatyev
Thu, 02 Aug 2018 14:40:55 -0700
changeset 51287 7b1ddbafa134
parent 47216 71c04702a3d5
permissions -rw-r--r--
8208655: use JTreg skipped status in hotspot tests Reviewed-by: kvn, hseigel, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
     2
 * Copyright (c) 2014, 2016, 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
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    27
 * @library /test/lib
24454
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    28
 * @summary Test empty bootstrap_methods table within BootstrapMethods attribute
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 30604
diff changeset
    29
 * @modules java.base/jdk.internal.misc
29678
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;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    36
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    37
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    38
import jdk.test.lib.JDKToolFinder;
24454
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 class TestEmptyBootstrapMethodsAttr {
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    41
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    42
    public static void main(String args[]) throws Throwable {
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    43
        System.out.println("Regression test for bug 8041918");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    44
        String jarFile = System.getProperty("test.src") + File.separator + "emptynumbootstrapmethods.jar";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    45
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    46
        // ====== extract the test case
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    47
        ProcessBuilder pb = new ProcessBuilder(new String[] { JDKToolFinder.getJDKTool("jar"), "xvf", jarFile } );
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    48
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    49
        output.shouldHaveExitValue(0);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    50
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    51
        // Test case #1:
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    52
        // Try loading class with empty bootstrap_methods table where no
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    53
        // other attributes are following BootstrapMethods in attribute table.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    54
        String className = "emptynumbootstrapmethods1";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    55
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    56
        // ======= execute test case #1
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    57
        // Expect a lack of main method, this implies that the class loaded correctly
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    58
        // with an empty bootstrap_methods and did not generate a ClassFormatError.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    59
        pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    60
        output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    61
        output.shouldNotContain("java.lang.ClassFormatError");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    62
        output.shouldContain("Main method not found in class " + className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    63
        output.shouldHaveExitValue(1);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    64
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    65
        // Test case #2:
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    66
        // Try loading class with empty bootstrap_methods table where an
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    67
        // AnnotationDefault attribute follows the BootstrapMethods in the attribute table.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    68
        className = "emptynumbootstrapmethods2";
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    69
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    70
        // ======= execute test case #2
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    71
        // Expect a lack of main method, this implies that the class loaded correctly
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    72
        // with an empty bootstrap_methods and did not generate ClassFormatError.
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    73
        pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    74
        output = new OutputAnalyzer(pb.start());
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    75
        output.shouldNotContain("java.lang.ClassFormatError");
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    76
        output.shouldContain("Main method not found in class " + className);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    77
        output.shouldHaveExitValue(1);
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    78
    }
19b3c54faec3 8041918: BootstrapMethods attribute cannot be empty.
lfoltan
parents:
diff changeset
    79
}