You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by da...@apache.org on 2019/11/22 19:45:24 UTC

[openjpa] branch 2.2.x updated: ConcurrentModificationException window when MetaDataRepository cache updated

This is an automated email from the ASF dual-hosted git repository.

dazeydev pushed a commit to branch 2.2.x
in repository https://gitbox.apache.org/repos/asf/openjpa.git


The following commit(s) were added to refs/heads/2.2.x by this push:
     new a68a0f1  ConcurrentModificationException window when MetaDataRepository cache updated
a68a0f1 is described below

commit a68a0f1d6884201b8f12e3f021154ec46694882f
Author: Will Dazey <da...@gmail.com>
AuthorDate: Thu Oct 24 11:40:24 2019 -0500

    ConcurrentModificationException window when MetaDataRepository cache updated
    
    Signed-off-by: Will Dazey <da...@gmail.com>
---
 .../org/apache/openjpa/meta/MetaDataRepository.java | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
index 3c1884f..6dcb8de 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
@@ -1629,14 +1629,21 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
      *  before other threads attempt to call this method
      */
     synchronized Class<?>[] processRegisteredClasses(ClassLoader envLoader) {
-        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()]);
-        _registered.clear();
+        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
+            reg = _registered.toArray(new Class[_registered.size()]);
+            _registered.clear();
+        }
 
         Collection<String> pcNames = getPersistentTypeNames(false, envLoader);
         Collection<Class<?>> failed = null;