Skip to content

Commit b99bff9

Browse files
committed
8337622: IllegalArgumentException in java.lang.reflect.Field.get
Backport-of: 41e31d6
1 parent 2518544 commit b99bff9

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,19 +1435,12 @@ void java_lang_Class::compute_offsets() {
14351435

14361436
InstanceKlass* k = vmClasses::Class_klass();
14371437
CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1438-
1439-
// Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1440-
// init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1441-
// GC treats them the same.
1442-
_init_lock_offset = _component_mirror_offset;
1443-
14441438
CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
14451439
}
14461440

14471441
#if INCLUDE_CDS
14481442
void java_lang_Class::serialize_offsets(SerializeClosure* f) {
14491443
f->do_bool(&_offsets_computed);
1450-
f->do_u4((u4*)&_init_lock_offset);
14511444

14521445
CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
14531446

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class java_lang_String : AllStatic {
208208
macro(java_lang_Class, protection_domain, object_signature, false) \
209209
macro(java_lang_Class, signers, object_signature, false) \
210210
macro(java_lang_Class, source_file, object_signature, false) \
211+
macro(java_lang_Class, init_lock, object_signature, false)
211212

212213
class java_lang_Class : AllStatic {
213214
friend class VMStructs;
Lines changed: 50 additions & 0 deletions
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)