Skip to content

Commit 05d82ab

Browse files
committed
8367912: Add unit test for LoadableDescriptors attribute with invalid entries
1 parent 443cdd5 commit 05d82ab

File tree

2 files changed

+258
-0
lines changed

2 files changed

+258
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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+
// This file contains a class file with an invalid entry in its
26+
// LoadableDescriptors attribute. The class file has been generated
27+
// from the source below with editing to the constant pool and
28+
// the LoadableDescriptors attribute.
29+
//
30+
//
31+
// import jdk.internal.vm.annotation.NullRestricted;
32+
// import jdk.internal.vm.annotation.Strict;
33+
//
34+
//
35+
// public class LDTest {
36+
// static value class Point {
37+
// short s0, s1;
38+
// Point(short sa, short sb) {
39+
// s0 = sa;
40+
// s1 = sb;
41+
// }
42+
// }
43+
//
44+
// @Strict
45+
// @NullRestricted
46+
// Point p = new Point((short)0, (short)0);
47+
//
48+
// public static void main(String[] args) {
49+
// LDTest test = new LDTest();
50+
// }
51+
// }
52+
53+
54+
class LDTest {
55+
0xCAFEBABE;
56+
65535; // minor version
57+
70; // version
58+
[] { // Constant Pool
59+
; // first element is empty
60+
class #2; // #1
61+
Utf8 "LDTest$Point"; // #2
62+
Method #1 #4; // #3
63+
NameAndType #5 #6; // #4
64+
Utf8 "<init>"; // #5
65+
Utf8 "(SS)V"; // #6
66+
Field #8 #9; // #7
67+
class #10; // #8
68+
NameAndType #11 #12; // #9
69+
Utf8 "LDTest"; // #10
70+
Utf8 "p"; // #11
71+
Utf8 "LLDTest$Point;"; // #12
72+
Method #14 #15; // #13
73+
class #16; // #14
74+
NameAndType #5 #17; // #15
75+
Utf8 "java/lang/Object"; // #16
76+
Utf8 "()V"; // #17
77+
Method #8 #15; // #18
78+
Utf8 "RuntimeVisibleAnnotations"; // #19
79+
Utf8 "Ljdk/internal/vm/annotation/NullRestricted;"; // #20
80+
Utf8 "RuntimeInvisibleAnnotations"; // #21
81+
Utf8 "Ljdk/internal/vm/annotation/Strict;"; // #22
82+
Utf8 "Code"; // #23
83+
Utf8 "LineNumberTable"; // #24
84+
Utf8 "main"; // #25
85+
Utf8 "([Ljava/lang/String;)V"; // #26
86+
Utf8 "SourceFile"; // #27
87+
Utf8 "LDTest.java"; // #28
88+
Utf8 "NestMembers"; // #29
89+
Utf8 "InnerClasses"; // #30
90+
Utf8 "Point"; // #31
91+
Utf8 "LoadableDescriptors"; // #32
92+
Utf8 "[V"; // #33 // <== new invalid descriptor
93+
} // Constant Pool
94+
95+
0x0021; // access
96+
#8;// this_cpx
97+
#14;// super_cpx
98+
99+
[] { // Interfaces
100+
} // Interfaces
101+
102+
[] { // Fields
103+
{ // field
104+
0x0800; // access
105+
#11; // name_index
106+
#12; // descriptor_index
107+
[] { // Attributes
108+
Attr(#19) { // RuntimeVisibleAnnotations
109+
[] { // annotations
110+
{ // annotation
111+
#20;
112+
[] { // element_value_pairs
113+
} // element_value_pairs
114+
} // annotation
115+
}
116+
} // end RuntimeVisibleAnnotations
117+
;
118+
Attr(#21) { // RuntimeInvisibleAnnotations
119+
[] { // annotations
120+
{ // annotation
121+
#22;
122+
[] { // element_value_pairs
123+
} // element_value_pairs
124+
} // annotation
125+
}
126+
} // end RuntimeInvisibleAnnotations
127+
} // Attributes
128+
}
129+
} // Fields
130+
131+
[] { // Methods
132+
{ // method
133+
0x0001; // access
134+
#5; // name_index
135+
#17; // descriptor_index
136+
[] { // Attributes
137+
Attr(#23) { // Code
138+
5; // max_stack
139+
1; // max_locals
140+
Bytes[]{
141+
0x2ABB0001590303B7;
142+
0x0003B500072AB700;
143+
0x0DB1;
144+
}
145+
[] { // Traps
146+
} // end Traps
147+
[] { // Attributes
148+
Attr(#24) { // LineNumberTable
149+
[] { // line_number_table
150+
0 14;
151+
13 5;
152+
17 14;
153+
}
154+
} // end LineNumberTable
155+
} // Attributes
156+
} // end Code
157+
} // Attributes
158+
}
159+
;
160+
{ // method
161+
0x0009; // access
162+
#25; // name_index
163+
#26; // descriptor_index
164+
[] { // Attributes
165+
Attr(#23) { // Code
166+
2; // max_stack
167+
2; // max_locals
168+
Bytes[]{
169+
0xBB000859B700124C;
170+
0xB1;
171+
}
172+
[] { // Traps
173+
} // end Traps
174+
[] { // Attributes
175+
Attr(#24) { // LineNumberTable
176+
[] { // line_number_table
177+
0 19;
178+
8 20;
179+
}
180+
} // end LineNumberTable
181+
} // Attributes
182+
} // end Code
183+
} // Attributes
184+
}
185+
} // Methods
186+
187+
[] { // Attributes
188+
Attr(#27) { // SourceFile
189+
#28;
190+
} // end SourceFile
191+
;
192+
Attr(#29) { // NestMembers
193+
[] { // classes
194+
#1;
195+
}
196+
} // end NestMembers
197+
;
198+
Attr(#30) { // InnerClasses
199+
[] { // classes
200+
#1 #8 #31 24;
201+
}
202+
} // end InnerClasses
203+
;
204+
Attr(#32) { // LoadableDescriptors
205+
0x00010021; // <== modified index to contant pool
206+
} // end LoadableDescriptors
207+
} // Attributes
208+
} // end class LDTest
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
* @test
26+
* @summary test a LoadableDescriptors attribute with an invalid entry
27+
* @enablePreview
28+
* @compile LDTest.jcod TestIllegalLoadableDescriptors.java
29+
* @run main/othervm TestIllegalLoadableDescriptors
30+
*/
31+
32+
33+
public class TestIllegalLoadableDescriptors {
34+
35+
public static void main(String[] args) throws ClassNotFoundException {
36+
boolean gotException = false;
37+
try {
38+
Class newClass = Class.forName("LDTest");
39+
} catch (java.lang.ClassFormatError e) {
40+
gotException = true;
41+
if (!e.getMessage().contains("Descriptor from LoadableDescriptors attribute at index \"33\" in class LDTest has illegal signature \"[V")) {
42+
throw new RuntimeException( "Wrong ClassFormatError: " + e.getMessage());
43+
}
44+
}
45+
if (!gotException) {
46+
throw new RuntimeException("Missing ClassFormatError");
47+
}
48+
}
49+
50+
}

0 commit comments

Comments
 (0)