Skip to content

Commit db32304

Browse files
committed
8365526: Crash with null Symbol passed to SystemDictionary::resolve_or_null
Reviewed-by: mdoerr Backport-of: 8ed7c23fa02f7c40cceefb24f92a3df281d12c4f
1 parent cad9706 commit db32304

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/hotspot/share/classfile/resolutionErrors.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void ResolutionErrorTable::add_entry(int index, unsigned int hash,
4646
entry->set_cp_index(cp_index);
4747
entry->set_error(error);
4848
entry->set_message(message);
49-
entry->set_nest_host_error(NULL);
49+
entry->init_nest_host_error(NULL);
5050
entry->set_cause(cause);
5151
entry->set_cause_msg(cause_msg);
5252

@@ -63,7 +63,7 @@ void ResolutionErrorTable::add_entry(int index, unsigned int hash,
6363

6464
ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool());
6565
entry->set_cp_index(cp_index);
66-
entry->set_nest_host_error(message);
66+
entry->init_nest_host_error(message);
6767
entry->set_error(NULL);
6868
entry->set_message(NULL);
6969
entry->set_cause(NULL);
@@ -112,6 +112,14 @@ void ResolutionErrorEntry::set_cause_msg(const char* c) {
112112

113113
// The incoming nest host error message is already in the C-Heap.
114114
void ResolutionErrorEntry::set_nest_host_error(const char* message) {
115+
// If a message is already set, free it.
116+
if (nest_host_error() != nullptr) {
117+
FREE_C_HEAP_ARRAY(char, _nest_host_error);
118+
}
119+
init_nest_host_error(message);
120+
}
121+
122+
void ResolutionErrorEntry::init_nest_host_error(const char* message) {
115123
_nest_host_error = message;
116124
}
117125

src/hotspot/share/classfile/resolutionErrors.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class ResolutionErrorEntry : public HashtableEntry<ConstantPool*, mtClass> {
122122
void set_cause_msg(const char* c);
123123

124124
const char* nest_host_error() const { return _nest_host_error; }
125+
void init_nest_host_error(const char* message);
125126
// The incoming nest host error message is already in the C-Heap.
126127
void set_nest_host_error(const char* message);
127128

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,14 +1896,19 @@ void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
18961896
{
18971897
MutexLocker ml(Thread::current(), SystemDictionary_lock);
18981898
ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
1899-
if (entry != NULL && entry->nest_host_error() == NULL) {
1899+
if (entry == NULL) {
1900+
// Only add a new entry to the resolution error table if one hasn't been found for this
1901+
// constant pool index. In this case resolution succeeded but there's an error in this nest host
1902+
// that we use the table to record.
1903+
assert(pool->resolved_klass_at(which) != nullptr, "klass should be resolved if there is no entry");
1904+
resolution_errors()->add_entry(index, hash, pool, which, message);
1905+
} else {
19001906
// An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we
19011907
// still want to add the error message for the higher-level access checks to report. We should
19021908
// only reach here under the same error condition, so we can ignore the potential race with setting
1903-
// the message. If we see it is already set then we can ignore it.
1909+
// the message, and set it again.
1910+
assert(entry->nest_host_error() == nullptr || strcmp(entry->nest_host_error(), message) == 0, "should be the same message");
19041911
entry->set_nest_host_error(message);
1905-
} else {
1906-
resolution_errors()->add_entry(index, hash, pool, which, message);
19071912
}
19081913
}
19091914
}

0 commit comments

Comments
 (0)