Thu, 15 May 2014 09:25:27 -0400
8041918: BootstrapMethods attribute cannot be empty.
Summary: Allow a BootstrapMethods attribute that contains an empty bootstrap_methods table where num_bootstrap_methods is equal to zero.
Reviewed-by: coleenp, hseigel
1.1 --- a/src/share/vm/classfile/classFileParser.cpp Sun May 18 00:25:06 2014 +0400 1.2 +++ b/src/share/vm/classfile/classFileParser.cpp Thu May 15 09:25:27 2014 -0400 1.3 @@ -2777,7 +2777,7 @@ 1.4 "Short length on BootstrapMethods in class file %s", 1.5 CHECK); 1.6 1.7 - guarantee_property(attribute_byte_length > sizeof(u2), 1.8 + guarantee_property(attribute_byte_length >= sizeof(u2), 1.9 "Invalid BootstrapMethods attribute length %u in class file %s", 1.10 attribute_byte_length, 1.11 CHECK);
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/runtime/classFileParserBug/TestEmptyBootstrapMethodsAttr.java Thu May 15 09:25:27 2014 -0400 2.3 @@ -0,0 +1,75 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test TestEmptyBootstrapMethodsAttr 2.29 + * @bug 8041918 2.30 + * @library /testlibrary 2.31 + * @summary Test empty bootstrap_methods table within BootstrapMethods attribute 2.32 + * @compile TestEmptyBootstrapMethodsAttr.java 2.33 + * @run main TestEmptyBootstrapMethodsAttr 2.34 + */ 2.35 + 2.36 +import java.io.File; 2.37 +import com.oracle.java.testlibrary.*; 2.38 + 2.39 +public class TestEmptyBootstrapMethodsAttr { 2.40 + 2.41 + public static void main(String args[]) throws Throwable { 2.42 + System.out.println("Regression test for bug 8041918"); 2.43 + String jarFile = System.getProperty("test.src") + File.separator + "emptynumbootstrapmethods.jar"; 2.44 + 2.45 + // ====== extract the test case 2.46 + ProcessBuilder pb = new ProcessBuilder(new String[] { JDKToolFinder.getJDKTool("jar"), "xvf", jarFile } ); 2.47 + OutputAnalyzer output = new OutputAnalyzer(pb.start()); 2.48 + output.shouldHaveExitValue(0); 2.49 + 2.50 + // Test case #1: 2.51 + // Try loading class with empty bootstrap_methods table where no 2.52 + // other attributes are following BootstrapMethods in attribute table. 2.53 + String className = "emptynumbootstrapmethods1"; 2.54 + 2.55 + // ======= execute test case #1 2.56 + // Expect a lack of main method, this implies that the class loaded correctly 2.57 + // with an empty bootstrap_methods and did not generate a ClassFormatError. 2.58 + pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className); 2.59 + output = new OutputAnalyzer(pb.start()); 2.60 + output.shouldNotContain("java.lang.ClassFormatError"); 2.61 + output.shouldContain("Main method not found in class " + className); 2.62 + output.shouldHaveExitValue(1); 2.63 + 2.64 + // Test case #2: 2.65 + // Try loading class with empty bootstrap_methods table where an 2.66 + // AnnotationDefault attribute follows the BootstrapMethods in the attribute table. 2.67 + className = "emptynumbootstrapmethods2"; 2.68 + 2.69 + // ======= execute test case #2 2.70 + // Expect a lack of main method, this implies that the class loaded correctly 2.71 + // with an empty bootstrap_methods and did not generate ClassFormatError. 2.72 + pb = ProcessTools.createJavaProcessBuilder("-cp", ".", className); 2.73 + output = new OutputAnalyzer(pb.start()); 2.74 + output.shouldNotContain("java.lang.ClassFormatError"); 2.75 + output.shouldContain("Main method not found in class " + className); 2.76 + output.shouldHaveExitValue(1); 2.77 + } 2.78 +}
3.1 Binary file test/runtime/classFileParserBug/emptynumbootstrapmethods.jar has changed
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/runtime/classFileParserBug/emptynumbootstrapmethods1.jcod Thu May 15 09:25:27 2014 -0400 4.3 @@ -0,0 +1,68 @@ 4.4 +/* 4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * This test contains a BootstrapMethods attribute with an empty 4.29 + * bootstrap_methods table. This yields a BootstrapMethods 4.30 + * attribute length of 2 and should not cause a 4.31 + * java.lang.ClassFormatError to be thrown. 4.32 + */ 4.33 +class emptynumbootstrapmethods1 { 4.34 + 0xCAFEBABE; 4.35 + 0; // minor version 4.36 + 51; // version 4.37 + [12] { // Constant Pool 4.38 + ; // first element is empty 4.39 + class #2; // #1 at 0x0A 4.40 + Utf8 "emptynumbootstrapmethods1"; // #2 at 0x0D 4.41 + class #4; // #3 at 0x1F 4.42 + Utf8 "java/lang/Object"; // #4 at 0x22 4.43 + MethodHandle 5b #9; // #5 at 0x35 4.44 + NameAndType #7 #8; // #6 at 0x39 4.45 + Utf8 "equals"; // #7 at 0x3E 4.46 + Utf8 "(Ljava/lang/Object;)Z"; // #8 at 0x47 4.47 + Method #3 #6; // #9 at 0x5F 4.48 + Utf8 "equalsx"; // #10 at 0x3E 4.49 + Utf8 "BootstrapMethods"; // #11 at 0x69 4.50 + } // Constant Pool 4.51 + 4.52 + 0x0001; // access 4.53 + #1;// this_cpx 4.54 + #3;// super_cpx 4.55 + 4.56 + [0] { // Interfaces 4.57 + } // Interfaces 4.58 + 4.59 + [0] { // fields 4.60 + } // fields 4.61 + 4.62 + [0] { // methods 4.63 + } // methods 4.64 + 4.65 + [1] { // Attributes 4.66 + Attr(#11, 2) { // BootstrapMethods at 0x8A 4.67 + [0] { // bootstrap_methods 4.68 + } 4.69 + } // end BootstrapMethods 4.70 + } // Attributes 4.71 +} // end class atrbsm00101m10p
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/runtime/classFileParserBug/emptynumbootstrapmethods2.jcod Thu May 15 09:25:27 2014 -0400 5.3 @@ -0,0 +1,89 @@ 5.4 +/* 5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * This test contains a BootstrapMethods attribute with an empty 5.29 + * bootstrap_methods table. This yields a BootstrapMethods 5.30 + * attribute length of 2 and should not cause a 5.31 + * java.lang.ClassFormatError to be thrown. To ensure that an empty 5.32 + * bootstrap_methods table is parsed correctly, another attribute, 5.33 + * AnnotationDefault, follows the BootstrapMethods attribute in 5.34 + * the attribute table. 5.35 + */ 5.36 + 5.37 +class emptynumbootstrapmethods2 { 5.38 + 0xCAFEBABE; 5.39 + 0; // minor version 5.40 + 51; // version 5.41 + [14] { // Constant Pool 5.42 + ; // first element is empty 5.43 + class #2; // #1 at 0x0A 5.44 + Utf8 "emptynumbootstrapmethods2"; // #2 at 0x0D 5.45 + class #4; // #3 at 0x1F 5.46 + Utf8 "java/lang/Object"; // #4 at 0x22 5.47 + MethodHandle 5b #9; // #5 at 0x35 5.48 + NameAndType #7 #8; // #6 at 0x39 5.49 + Utf8 "equals"; // #7 at 0x3E 5.50 + Utf8 "(Ljava/lang/Object;)Z"; // #8 at 0x47 5.51 + Method #3 #6; // #9 at 0x5F 5.52 + Utf8 "equalsx"; // #10 at 0x3E 5.53 + Utf8 "BootstrapMethods"; // #11 at 0x69 5.54 + Utf8 "AnnotationDefault"; // #12 5.55 + Utf8 "LAnnotationDefaultI;"; // #13 5.56 + } // Constant Pool 5.57 + 5.58 + 0x0001; // access 5.59 + #1;// this_cpx 5.60 + #3;// super_cpx 5.61 + 5.62 + [0] { // Interfaces 5.63 + } // Interfaces 5.64 + 5.65 + [0] { // fields 5.66 + } // fields 5.67 + 5.68 + [0] { // methods 5.69 + } // methods 5.70 + 5.71 + [2] { // Attributes 5.72 + Attr(#11, 2) { // BootstrapMethods at 0x8A 5.73 + [0] { // bootstrap_methods 5.74 + } 5.75 + } // end BootstrapMethods 5.76 + ; 5.77 + Attr(#12) { // AnnotationDefault 5.78 + [] { // type annotations 5.79 + { // type annotation 5.80 + 0x00; // target_type 5.81 + 0x00; // type_parameter_index 5.82 + []b { // type_path 5.83 + } 5.84 + 5.85 + #13; // type_index 5.86 + [] { // element_value_pairs 5.87 + } // element_value_pairs 5.88 + } // type annotation 5.89 + } // type annotations 5.90 + } // end AnnotationDefault 5.91 + } // Attributes 5.92 +} // end class atrbsm00101m10p