This is an automated email from the ASF dual-hosted git repository.
dazeydev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git
The following commit(s) were added to refs/heads/master by this push:
new b27175b ConcurrentModificationException window when
MetaDataRepository cache updated
b27175b is described below
commit b27175be87a3e4e9d88350158ad414e865ceab3b
Author: Will Dazey <[email protected]>
AuthorDate: Fri Nov 22 11:26:26 2019 -0600
ConcurrentModificationException window when MetaDataRepository cache updated
Signed-off-by: Will Dazey <[email protected]>
---
.../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 c1c0ca7..94c1fb6 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
@@ -1648,14 +1648,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;