Skip to content

Commit 41e31d6

Browse files
committedAug 12, 2024
8337622: IllegalArgumentException in java.lang.reflect.Field.get
Reviewed-by: dholmes, shade
1 parent 2ca136a commit 41e31d6

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed
 

‎src/hotspot/share/classfile/javaClasses.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -1452,19 +1452,12 @@ void java_lang_Class::compute_offsets() {
14521452

14531453
InstanceKlass* k = vmClasses::Class_klass();
14541454
CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1455-
1456-
// Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1457-
// init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1458-
// GC treats them the same.
1459-
_init_lock_offset = _component_mirror_offset;
1460-
14611455
CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
14621456
}
14631457

14641458
#if INCLUDE_CDS
14651459
void java_lang_Class::serialize_offsets(SerializeClosure* f) {
14661460
f->do_bool(&_offsets_computed);
1467-
f->do_u4((u4*)&_init_lock_offset);
14681461

14691462
CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
14701463

‎src/hotspot/share/classfile/javaClasses.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class java_lang_String : AllStatic {
209209
macro(java_lang_Class, static_oop_field_count, int_signature, false) \
210210
macro(java_lang_Class, protection_domain, object_signature, false) \
211211
macro(java_lang_Class, source_file, object_signature, false) \
212+
macro(java_lang_Class, init_lock, object_signature, false)
212213

213214
class java_lang_Class : AllStatic {
214215
friend class VMStructs;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2024, 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+
* @bug 8337622
27+
* @summary (reflect) java.lang.Class componentType field not found.
28+
* @library /test/lib
29+
* @modules java.base/java.lang:open
30+
* @run main ComponentTypeFieldTest
31+
*/
32+
33+
import java.lang.reflect.Field;
34+
import static jdk.test.lib.Asserts.*;
35+
36+
public class ComponentTypeFieldTest {
37+
38+
public static void main(String[] args) throws Exception {
39+
Field f = Class.class.getDeclaredField("componentType");
40+
f.setAccessible(true);
41+
Object val = f.get(Runnable.class);
42+
assertTrue(val == null);
43+
System.out.println("val is " + val);
44+
45+
Object arrayVal = f.get(Integer[].class);
46+
System.out.println("val is " + arrayVal);
47+
String arrayValString = arrayVal.toString();
48+
assertTrue(arrayValString.equals("class java.lang.Integer"));
49+
}
50+
}

0 commit comments

Comments
 (0)
Failed to load comments.