Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/classFileParserBug/TestEmptyBootstrapMethodsAttr.java
32284 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test TestEmptyBootstrapMethodsAttr25* @bug 804191826* @library /testlibrary27* @summary Test empty bootstrap_methods table within BootstrapMethods attribute28* @compile TestEmptyBootstrapMethodsAttr.java29* @run main TestEmptyBootstrapMethodsAttr30*/3132import java.io.File;33import com.oracle.java.testlibrary.*;3435public class TestEmptyBootstrapMethodsAttr {3637public static void main(String args[]) throws Throwable {38System.out.println("Regression test for bug 8041918");39String jarFile = System.getProperty("test.src") + File.separator + "emptynumbootstrapmethods.jar";4041// ====== extract the test case42ProcessBuilder pb = new ProcessBuilder(new String[] { JDKToolFinder.getJDKTool("jar"), "xvf", jarFile } );43OutputAnalyzer output = new OutputAnalyzer(pb.start());44output.shouldHaveExitValue(0);4546// Test case #1:47// Try loading class with empty bootstrap_methods table where no48// other attributes are following BootstrapMethods in attribute table.49String className = "emptynumbootstrapmethods1";5051// ======= execute test case #152// Expect a lack of main method, this implies that the class loaded correctly53// with an empty bootstrap_methods and did not generate a ClassFormatError.54pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);55output = new OutputAnalyzer(pb.start());56output.shouldNotContain("java.lang.ClassFormatError");57output.shouldContain("Main method not found in class " + className);58output.shouldHaveExitValue(1);5960// Test case #2:61// Try loading class with empty bootstrap_methods table where an62// AnnotationDefault attribute follows the BootstrapMethods in the attribute table.63className = "emptynumbootstrapmethods2";6465// ======= execute test case #266// Expect a lack of main method, this implies that the class loaded correctly67// with an empty bootstrap_methods and did not generate ClassFormatError.68pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className);69output = new OutputAnalyzer(pb.start());70output.shouldNotContain("java.lang.ClassFormatError");71output.shouldContain("Main method not found in class " + className);72output.shouldHaveExitValue(1);73}74}757677