You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2022/03/18 13:23:34 UTC

[sling-org-apache-sling-scripting-core] branch bugfix/SLING-11213 created (now ed46d43)

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

joerghoh pushed a change to branch bugfix/SLING-11213
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git.


      at ed46d43  SLING-11213 avoid ConcurrentModificationException

This branch includes the following new commits:

     new ed46d43  SLING-11213 avoid ConcurrentModificationException

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-scripting-core] 01/01: SLING-11213 avoid ConcurrentModificationException

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a commit to branch bugfix/SLING-11213
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git

commit ed46d4347ae7ece277426e62de5e484c50c8c1e6
Author: Jörg Hoh <jo...@joerghoh.de>
AuthorDate: Fri Mar 18 14:23:09 2022 +0100

    SLING-11213 avoid ConcurrentModificationException
---
 .../core/impl/jsr223/SlingScriptEngineManager.java     | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java b/src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java
index ca7a223..ac77167 100644
--- a/src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java
+++ b/src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java
@@ -422,15 +422,17 @@ public class SlingScriptEngineManager extends ScriptEngineManager implements Bun
             }
             // and finally factories registered as OSGi services
             if (bundleContext != null) {
-                for (final ServiceReference<ScriptEngineFactory> serviceReference : serviceReferences) {
-                    final ScriptEngineFactory scriptEngineFactory = bundleContext.getService(serviceReference);
-                    if (isIncluded(scriptEngineFactory)) {
-                        final Map<String, Object> factoryProperties = new HashMap<>(serviceReference.getPropertyKeys().length);
-                        for (final String key : serviceReference.getPropertyKeys()) {
-                            factoryProperties.put(key, serviceReference.getProperty(key));
+                synchronized (this.serviceReferences) {
+                    for (final ServiceReference<ScriptEngineFactory> serviceReference : serviceReferences) {
+                        final ScriptEngineFactory scriptEngineFactory = bundleContext.getService(serviceReference);
+                        if (isIncluded(scriptEngineFactory)) {
+                            final Map<String, Object> factoryProperties = new HashMap<>(serviceReference.getPropertyKeys().length);
+                            for (final String key : serviceReference.getPropertyKeys()) {
+                                factoryProperties.put(key, serviceReference.getProperty(key));
+                            }
+                            final SortableScriptEngineFactory sortableScriptEngineFactory = new SortableScriptEngineFactory(scriptEngineFactory, serviceReference.getBundle().getBundleId(), PropertiesUtil.toInteger(serviceReference.getProperty(Constants.SERVICE_RANKING), 0), factoryProperties);
+                            factories.add(sortableScriptEngineFactory);
                         }
-                        final SortableScriptEngineFactory sortableScriptEngineFactory = new SortableScriptEngineFactory(scriptEngineFactory, serviceReference.getBundle().getBundleId(), PropertiesUtil.toInteger(serviceReference.getProperty(Constants.SERVICE_RANKING), 0), factoryProperties);
-                        factories.add(sortableScriptEngineFactory);
                     }
                 }
             }