karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [karaf] branch master updated: [KARAF-6337] Prevent ConcurrentModificationException
Date Sun, 08 Sep 2019 04:38:54 GMT
This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new df405bd  [KARAF-6337] Prevent ConcurrentModificationException
     new 296023e  Merge pull request #905 from seeburger-ag/KARAF-6337
df405bd is described below

commit df405bd50660a8abbc0ee33fde536c35b9fe5c5e
Author: Rico Neubauer <R.Neubauer@seeburger.de>
AuthorDate: Wed Jul 31 15:45:30 2019 +0200

    [KARAF-6337] Prevent ConcurrentModificationException
    
    when iterating over system properties
---
 .../org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java  | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
index b496add..4f063af 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
@@ -26,6 +26,7 @@ import java.nio.file.Paths;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
 
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
@@ -68,8 +69,11 @@ public class HeadlessSessionImpl implements Session {
         session = processor.createSession(in, out, err);
         if (parent == null) {
             Properties sysProps = System.getProperties();
-            for (Object key : sysProps.keySet()) {
-                session.put(key.toString(), sysProps.get(key));
+            // iterating over sysProps.keySet() directly is not thread-safe and may throw
ConcurrentMod.Ex.,
+            // so first get the keys and then query their values
+            Set<String> keys = sysProps.stringPropertyNames();
+            for (String key : keys) {
+                session.put(key, sysProps.getProperty(key)); // value can be null if removed
in meantime, but unlikely
             }
         }
         session.put(".processor", processor);


Mime
View raw message