ConcurrentModificationException window when MetaDataRepository cache updated

Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
This commit is contained in:
Will Dazey 2019-11-22 11:26:26 -06:00
parent ef98e18480
commit b27175be87
1 changed files with 14 additions and 7 deletions

View File

@ -1648,14 +1648,21 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
* before other threads attempt to call this method
*/
synchronized Class<?>[] processRegisteredClasses(ClassLoader envLoader) {
Class<?>[] reg;
/*Synchronize `_registered` cache to block MetaDataRepository.register() from adding
* to the cache while we copy, causing a ConcurrentModificationException
*/
synchronized (_registered) {
if (_registered.isEmpty()) {
return EMPTY_CLASSES;
}
// copy into new collection to avoid concurrent mod errors on reentrant
// registrations
Class<?>[] reg = _registered.toArray(new Class[_registered.size()]);
reg = _registered.toArray(new Class[_registered.size()]);
_registered.clear();
}
Collection<String> pcNames = getPersistentTypeNames(false, envLoader);
Collection<Class<?>> failed = null;