Skip to content

Commit b98114f

Browse files
committed
8365526: Crash with null Symbol passed to SystemDictionary::resolve_or_null
Reviewed-by: dholmes, never, jsjolen
1 parent 785ca67 commit b98114f

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/hotspot/share/classfile/resolutionErrors.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_inde
7373

7474
ResolutionErrorKey key(pool(), cp_index);
7575
ResolutionErrorEntry *entry = new ResolutionErrorEntry(error, message, cause, cause_msg);
76-
_resolution_error_table->put(key, entry);
76+
_resolution_error_table->put_when_absent(key, entry);
7777
}
7878

7979
// create new nest host error entry
@@ -85,7 +85,7 @@ void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_inde
8585

8686
ResolutionErrorKey key(pool(), cp_index);
8787
ResolutionErrorEntry *entry = new ResolutionErrorEntry(message);
88-
_resolution_error_table->put(key, entry);
88+
_resolution_error_table->put_when_absent(key, entry);
8989
}
9090

9191
// find entry in the table
@@ -126,6 +126,15 @@ ResolutionErrorEntry::~ResolutionErrorEntry() {
126126
}
127127
}
128128

129+
void ResolutionErrorEntry::set_nest_host_error(const char* message) {
130+
// If a message is already set, free it.
131+
if (nest_host_error() != nullptr) {
132+
FREE_C_HEAP_ARRAY(char, _nest_host_error);
133+
}
134+
_nest_host_error = message;
135+
}
136+
137+
129138
class ResolutionErrorDeleteIterate : StackObj {
130139
ConstantPool* p;
131140

src/hotspot/share/classfile/resolutionErrors.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -91,10 +91,7 @@ class ResolutionErrorEntry : public CHeapObj<mtClass> {
9191
~ResolutionErrorEntry();
9292

9393
// The incoming nest host error message is already in the C-Heap.
94-
void set_nest_host_error(const char* message) {
95-
_nest_host_error = message;
96-
}
97-
94+
void set_nest_host_error(const char* message);
9895

9996
Symbol* error() const { return _error; }
10097
const char* message() const { return _message; }

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,14 +1864,19 @@ void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
18641864
{
18651865
MutexLocker ml(Thread::current(), SystemDictionary_lock);
18661866
ResolutionErrorEntry* entry = ResolutionErrorTable::find_entry(pool, which);
1867-
if (entry != nullptr && entry->nest_host_error() == nullptr) {
1867+
if (entry == nullptr) {
1868+
// Only add a new entry to the resolution error table if one hasn't been found for this
1869+
// constant pool index. In this case resolution succeeded but there's an error in this nest host
1870+
// that we use the table to record.
1871+
assert(pool->resolved_klass_at(which) != nullptr, "klass should be resolved if there is no entry");
1872+
ResolutionErrorTable::add_entry(pool, which, message);
1873+
} else {
18681874
// An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we
18691875
// still want to add the error message for the higher-level access checks to report. We should
18701876
// only reach here under the same error condition, so we can ignore the potential race with setting
1871-
// the message. If we see it is already set then we can ignore it.
1877+
// the message, and set it again.
1878+
assert(entry->nest_host_error() == nullptr || strcmp(entry->nest_host_error(), message) == 0, "should be the same message");
18721879
entry->set_nest_host_error(message);
1873-
} else {
1874-
ResolutionErrorTable::add_entry(pool, which, message);
18751880
}
18761881
}
18771882
}

0 commit comments

Comments
 (0)