diff --git a/src/hotspot/share/classfile/resolutionErrors.cpp b/src/hotspot/share/classfile/resolutionErrors.cpp index 25aa370d2571a..919fe0b6c2f22 100644 --- a/src/hotspot/share/classfile/resolutionErrors.cpp +++ b/src/hotspot/share/classfile/resolutionErrors.cpp @@ -85,7 +85,9 @@ void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_inde ResolutionErrorKey key(pool(), cp_index); ResolutionErrorEntry *entry = new ResolutionErrorEntry(message); - _resolution_error_table->put(key, entry); + bool created = false; + _resolution_error_table->put_if_absent(key, entry, &created); + assert(created, "should be created not updated"); } // find entry in the table diff --git a/src/hotspot/share/classfile/systemDictionary.cpp b/src/hotspot/share/classfile/systemDictionary.cpp index 5c49a32b8d04d..fb4974c4a7f13 100644 --- a/src/hotspot/share/classfile/systemDictionary.cpp +++ b/src/hotspot/share/classfile/systemDictionary.cpp @@ -1864,14 +1864,17 @@ void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool, { MutexLocker ml(Thread::current(), SystemDictionary_lock); ResolutionErrorEntry* entry = ResolutionErrorTable::find_entry(pool, which); - if (entry != nullptr && entry->nest_host_error() == nullptr) { + if (entry == nullptr) { + // Only add a new resolution error if one hasn't been found for this constant pool index. In this case, + // resolution succeeded but there's an error in this nest host. + assert(pool->resolved_klass_at(which) != nullptr, "klass is should be resolved if there is no entry"); + ResolutionErrorTable::add_entry(pool, which, message); + } else if (entry->nest_host_error() == nullptr) { // An existing entry means we had a true resolution failure (LinkageError) with our nest host, but we // still want to add the error message for the higher-level access checks to report. We should // only reach here under the same error condition, so we can ignore the potential race with setting // the message. If we see it is already set then we can ignore it. entry->set_nest_host_error(message); - } else { - ResolutionErrorTable::add_entry(pool, which, message); } } }