1 /*
2 * Copyright (c) 2025, 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 /*
26 class OuterTest2 {
27 interface Greeting {
28 void sayHello();
29 }
30
31 public static void test2() throws ClassFormatError {
32 Greeting greeting = new Greeting() {
33 @Override
34 public void sayHello() {
35 System.out.println("Hello from an anonymous inner class!");
36 }
37 };
38
39 greeting.sayHello(); // Calls the method in the anonymous inner class
40 }
41 }
42
43 Nested class acccess flags are made invalid in this jcod file, the inner class is unnamed.
44 */
45
46 class OuterTest2 {
47 0xCAFEBABE;
48 0; // minor version
49 71; // version
50 [] { // Constant Pool
51 ; // first element is empty
52 Method #2 #3; // #1
53 class #4; // #2
54 NameAndType #5 #6; // #3
55 Utf8 "java/lang/Object"; // #4
56 Utf8 "<init>"; // #5
57 Utf8 "()V"; // #6
58 class #8; // #7
59 Utf8 "OuterTest2$1"; // #8
60 Method #7 #3; // #9
61 InterfaceMethod #11 #12; // #10
62 class #13; // #11
63 NameAndType #14 #6; // #12
64 Utf8 "OuterTest2$Greeting"; // #13
65 Utf8 "sayHello"; // #14
66 class #16; // #15
67 Utf8 "OuterTest2"; // #16
68 Utf8 "Code"; // #17
69 Utf8 "LineNumberTable"; // #18
70 Utf8 "test2"; // #19
71 Utf8 "Exceptions"; // #20
72 class #22; // #21
73 Utf8 "java/lang/ClassFormatError"; // #22
74 Utf8 "SourceFile"; // #23
75 Utf8 "OuterTest2.java"; // #24
76 Utf8 "NestMembers"; // #25
77 Utf8 "InnerClasses"; // #26
78 Utf8 "Greeting"; // #27
79 } // Constant Pool
80
81 0x0020; // access
82 #15;// this_cpx
83 #2;// super_cpx
84
85 [] { // Interfaces
86 } // Interfaces
87
88 [] { // Fields
89 } // Fields
90
91 [] { // Methods
92 { // method
93 0x0000; // access
94 #5; // name_index
95 #6; // descriptor_index
96 [] { // Attributes
97 Attr(#17) { // Code
98 1; // max_stack
99 1; // max_locals
100 Bytes[]{
101 0x2AB70001B1;
102 }
103 [] { // Traps
104 } // end Traps
105 [] { // Attributes
106 Attr(#18) { // LineNumberTable
107 [] { // line_number_table
108 0 3;
109 }
110 } // end LineNumberTable
111 } // Attributes
112 } // end Code
113 } // Attributes
114 }
115 ;
116 { // method
117 0x0009; // access
118 #19; // name_index
119 #6; // descriptor_index
120 [] { // Attributes
121 Attr(#17) { // Code
122 2; // max_stack
123 1; // max_locals
124 Bytes[]{
125 0xBB000759B700094B;
126 0x2AB9000A0100B1;
127 }
128 [] { // Traps
129 } // end Traps
130 [] { // Attributes
131 Attr(#18) { // LineNumberTable
132 [] { // line_number_table
133 0 9;
134 8 16;
135 14 17;
136 }
137 } // end LineNumberTable
138 } // Attributes
139 } // end Code
140 ;
141 Attr(#20) { // Exceptions
142 [] { // Exceptions
143 #21;
144 }
145 } // end Exceptions
146 } // Attributes
147 }
148 } // Methods
149
150 [] { // Attributes
151 Attr(#23) { // SourceFile
152 #24;
153 } // end SourceFile
154 ;
155 Attr(#25) { // NestMembers
156 [] { // classes
157 #11;
158 #7;
159 }
160 } // end NestMembers
161 ;
162 Attr(#26) { // InnerClasses
163 [] { // classes
164 #7 #0 #0 0x0fff; // This access flag sets is_interface & is_final, so invalid.
165 #11 #15 #27 1544;
166 }
167 } // end InnerClasses
168 } // Attributes
169 } // end class OuterTest2