1 /*
2 * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * This test contains a CONSTANT_Dynamic_info structure, but the BootstrapMethods Attribute
26 * contains bootstrap_methods array with 0 elements. ClassFormatError expected.
27 */
28
29 /*
30 class CondyEmptyBSMArray1 {
31 CondyEmptyBSMArray1() {}
32 public static Object m() {
33 // ldc Dynamic where the CONSTANT_Dynamic_info bootstrap_method_attr_index points to slot #0
34 // in the bootstrap_methods array, however the BootstrapMethods array is empty.
35 // Outcome -> java.lang.ClassFormatError: Short length on BootstrapMethods in class file CondyEmptyBSMArray1
36 return of ldc's Object;
37 public static void main(String[] args) { return; }
38 }
39 */
40
41 class CondyEmptyBSMArray1 {
42 0xCAFEBABE;
43 0; // minor version
44 55; // version
45 [] { // Constant Pool
46 ; // first element is empty
47 Utf8 "java/lang/Object"; // #1
48 class #1; // #2
49 Utf8 "<init>"; // #3
50 Utf8 "()V"; // #4
51 NameAndType #3 #4; // #5
52 Method #2 #5; // #6
53 Utf8 "Code"; // #7
54 Utf8 "CondyEmptyBSMArray1"; // #8
55 class #8; // #9
56 Utf8 "bsm"; // #10
57 Utf8 "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;"; // #11
58 NameAndType #10 #11; // #12
59 Method #9 #12; // #13
60 MethodHandle 6b #13; // #14
61 Utf8 "name"; // #15
62 Utf8 "Ljava/lang/Object;"; // #16
63 NameAndType #15 #16; // #17
64 Dynamic 0s #17; // #18
65 Utf8 "m"; // #19
66 Utf8 "()Ljava/lang/Object;"; // #20
67 Utf8 "main"; // #21
68 Utf8 "([Ljava/lang/String;)V"; // #22
69 Utf8 "BootstrapMethods"; // #23
70 Utf8 "CondyEmptyBSMArray1"; // #24
71 class #24; // #25
72 } // Constant Pool
73
74 0x0020; // access ACC_SUPER
75 #25;// this_cpx
76 #2;// super_cpx
77
78 [] { // Interfaces
79 } // Interfaces
80
81 [] { // fields
82 } // fields
83
84 [] { // methods
85 { // Member
86 0x0001; // access
87 #3; // name_cpx
88 #4; // sig_cpx
89 [] { // Attributes
90 Attr(#7) { // Code
91 1; // max_stack
92 1; // max_locals
93 Bytes[]{
94 0x2AB70006B1;
95 }
96 [] { // Traps
97 } // end Traps
98 [] { // Attributes
99 } // Attributes
100 } // end Code
101 } // Attributes
102 } // Member
103 ;
104 { // Member
105 0x0009; // access
106 #19; // name_cpx
107 #20; // sig_cpx
108 [] { // Attributes
109 Attr(#7) { // Code
110 1; // max_stack
111 0; // max_locals
112 Bytes[]{
113 0x1212B0;
114 }
115 [] { // Traps
116 } // end Traps
117 [] { // Attributes
118 } // Attributes
119 } // end Code
120 } // Attributes
121 } // Member
122 ;
123 { // Member
124 0x0009; // access
125 #21; // name_cpx
126 #22; // sig_cpx
127 [] { // Attributes
128 Attr(#7) { // Code
129 0; // max_stack
130 1; // max_locals
131 Bytes[]{
132 0xB1;
133 }
134 [] { // Traps
135 } // end Traps
136 [] { // Attributes
137 } // Attributes
138 } // end Code
139 } // Attributes
140 } // Member
141 } // methods
142
143 [] { // Attributes
144 Attr(#23) { // BootstrapMethods
145 [0] { // bootstrap_methods
146 }
147 } // end BootstrapMethods
148 } // Attributes
149 } // end class CondyEmptyBSMArray1