Michiel Eggermont pushed to branch release/4.2 at cms-community / 
hippo-site-toolkit


Commits:
bf0c862d by Michiel Eggermont at 2017-07-04T15:57:03+02:00
HSTTWO-4078 Fix concurrent modification exception

Synchronize on load to prevent concurrent modification exceptions on
accessing the delegatee.

(cherry picked from commit a5b94c4)

- - - - -


1 changed file:

- 
components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelLazyLoadingChangedBySet.java


Changes:

=====================================
components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelLazyLoadingChangedBySet.java
=====================================
--- 
a/components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelLazyLoadingChangedBySet.java
+++ 
b/components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelLazyLoadingChangedBySet.java
@@ -19,17 +19,18 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.function.Predicate;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.lang.StringUtils;
-import org.hippoecm.hst.configuration.cache.HstNodeLoadingCache;
-import org.hippoecm.hst.configuration.internal.ConfigurationLockInfo;
 import org.hippoecm.hst.configuration.HstNodeTypes;
+import org.hippoecm.hst.configuration.cache.HstNodeLoadingCache;
 import org.hippoecm.hst.configuration.components.HstComponentConfiguration;
 import org.hippoecm.hst.configuration.components.HstComponentsConfiguration;
 import org.hippoecm.hst.configuration.internal.CanonicalInfo;
+import org.hippoecm.hst.configuration.internal.ConfigurationLockInfo;
 import org.hippoecm.hst.configuration.model.HstNode;
 import org.hippoecm.hst.configuration.model.ModelLoadingException;
 import org.hippoecm.hst.configuration.site.HstSite;
@@ -45,7 +46,7 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
 
     private static final Logger log = 
LoggerFactory.getLogger(ChannelLazyLoadingChangedBySet.class);
 
-    private transient Set<String> delegatee;
+    private Set<String> delegatee;
     private transient Set<String> usersWithMainConfigNodeChanges;
     private transient final HstSite previewHstSite;
     private transient final Channel channel;
@@ -67,7 +68,7 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
         this.hstNodeLoadingCache = hstNodeLoadingCache;
     }
 
-    private void load() {
+    private synchronized void load() {
         if (delegatee != null) {
             return;
         }
@@ -87,11 +88,11 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
         if (hstNodeLoadingCache != null && delegatee.size() > 0) {
             // filter all system users out because they are not manageable 
through the changed by set of a channel
             try (HstNodeLoadingCache.LazyCloseableSession lazyCloseableSession 
= hstNodeLoadingCache.createLazyCloseableSession()) {
-                final SecurityService securityService = 
((HippoWorkspace)lazyCloseableSession.getSession().getWorkspace()).getSecurityService();
+                final SecurityService securityService = ((HippoWorkspace) 
lazyCloseableSession.getSession().getWorkspace()).getSecurityService();
 
                 final Iterator<String> iterator = delegatee.iterator();
                 while (iterator.hasNext()) {
-                   String userId = iterator.next();
+                    String userId = iterator.next();
                     try {
                         final User user = securityService.getUser(userId);
                         if (user.isSystemUser()) {
@@ -122,7 +123,7 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
                                                     final Set<String> 
usersWithLock,
                                                     final String 
previewConfigurationPath) {
 
-        final boolean inherited = 
!((CanonicalInfo)item).getCanonicalPath().startsWith(previewConfigurationPath + 
"/");
+        final boolean inherited = !((CanonicalInfo) 
item).getCanonicalPath().startsWith(previewConfigurationPath + "/");
         if (inherited) {
             // skip inherited sitemap item changes as that is not supported 
currently
             return;
@@ -130,7 +131,7 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
         if (!(item instanceof ConfigurationLockInfo)) {
             return;
         }
-        String lockedBy = ((ConfigurationLockInfo)item).getLockedBy();
+        String lockedBy = ((ConfigurationLockInfo) item).getLockedBy();
         if (StringUtils.isNotBlank(lockedBy)) {
             usersWithLock.add(lockedBy);
         }
@@ -156,7 +157,7 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
         if (!(config instanceof ConfigurationLockInfo)) {
             return;
         }
-        String lockedBy = ((ConfigurationLockInfo)config).getLockedBy();
+        String lockedBy = ((ConfigurationLockInfo) config).getLockedBy();
         if (StringUtils.isNotBlank(lockedBy)) {
             usersWithLock.add(lockedBy);
         }
@@ -172,12 +173,12 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
             if (!(config instanceof ConfigurationLockInfo)) {
                 continue;
             }
-            final boolean inherited = 
!((CanonicalInfo)config).getCanonicalPath().startsWith(previewHstSite.getConfigurationPath()
 + "/");
+            final boolean inherited = !((CanonicalInfo) 
config).getCanonicalPath().startsWith(previewHstSite.getConfigurationPath() + 
"/");
             if (inherited) {
                 // skip inherited sitemenu item changes as that is not 
supported currently
                 continue;
             }
-            String lockedBy = ((ConfigurationLockInfo)config).getLockedBy();
+            String lockedBy = ((ConfigurationLockInfo) config).getLockedBy();
             addUserWithSiteMenuLock(lockedBy, usersWithLock);
         }
         return usersWithLock;
@@ -226,6 +227,11 @@ public class ChannelLazyLoadingChangedBySet implements 
Set<String> {
     }
 
     @Override
+    public boolean removeIf(final Predicate<? super String> filter) {
+        throw new UnsupportedOperationException("#removeIf not supported in 
ChannelLazyLoadingChangedBySet");
+    }
+
+    @Override
     public boolean add(final String string) {
         throw new UnsupportedOperationException("#add not supported in 
ChannelLazyLoadingChangedBySet");
     }



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/bf0c862d7a3a9f373d7dfe44e4cec8c343d1e718
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to