You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2019/12/02 15:17:15 UTC

[syncope] branch 2_1_X updated: [SYNCOPE-1520] Applying the suggested workaround

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

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new 2f621fc  [SYNCOPE-1520] Applying the suggested workaround
2f621fc is described below

commit 2f621fca20d67375d9cd49f2159aff582ef8da5e
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Mon Dec 2 16:13:53 2019 +0100

    [SYNCOPE-1520] Applying the suggested workaround
---
 .../persistence/jpa/dao/AbstractJPAJSONAnyDAO.java | 30 ++++++++++++----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractJPAJSONAnyDAO.java b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractJPAJSONAnyDAO.java
index b4407f8..de1cd45 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractJPAJSONAnyDAO.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractJPAJSONAnyDAO.java
@@ -44,6 +44,7 @@ import org.apache.syncope.core.persistence.api.entity.Any;
 import org.apache.syncope.core.persistence.api.entity.AnyUtils;
 import org.apache.syncope.core.persistence.api.entity.DerSchema;
 import org.apache.syncope.core.persistence.api.entity.JSONPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.PlainAttr;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
@@ -318,20 +319,21 @@ abstract class AbstractJPAJSONAnyDAO extends AbstractDAO<AbstractEntity> impleme
     @Override
     public <A extends Any<?>> void checkBeforeSave(final String table, final AnyUtils anyUtils, final A any) {
         // check UNIQUE constraints
-        any.getPlainAttrs().stream().
-                filter(attr -> attr.getUniqueValue() != null).
-                map(JSONPlainAttr.class::cast).
-                forEach(attr -> {
-                    PlainSchema schema = attr.getSchema();
-                    List<A> others = findByPlainAttrValue(table, anyUtils, schema, attr.getUniqueValue(), false);
-                    if (others.isEmpty() || (others.size() == 1 && others.get(0).getKey().equals(any.getKey()))) {
-                        LOG.debug("No duplicate value found for {}", attr.getUniqueValue().getValueAsString());
-                    } else {
-                        throw new DuplicateException(
-                                "Value " + attr.getUniqueValue().getValueAsString()
-                                + " existing for " + schema.getKey());
-                    }
-                });
+        // cannot move to functional style due to the same issue reported at
+        // https://medium.com/xiumeteo-labs/stream-and-concurrentmodificationexception-2d14ed8ff4b2
+        for (PlainAttr<?> attr : any.getPlainAttrs()) {
+            if (attr.getUniqueValue() != null && attr instanceof JSONPlainAttr) {
+                PlainSchema schema = attr.getSchema();
+                Optional<A> other = findByPlainAttrUniqueValue(table, anyUtils, schema, attr.getUniqueValue(), false);
+                if (!other.isPresent() || other.get().getKey().equals(any.getKey())) {
+                    LOG.debug("No duplicate value found for {}", attr.getUniqueValue().getValueAsString());
+                } else {
+                    throw new DuplicateException(
+                            "Value " + attr.getUniqueValue().getValueAsString()
+                            + " existing for " + schema.getKey());
+                }
+            }
+        }
 
         // update sysInfo - as org.apache.syncope.core.persistence.jpa.entity.PlainAttrListener is not invoked
         Date now = new Date();