Michael Blow has submitted this change and it was merged.

Change subject: [NO ISSUE] Take defensive copy of array options
......................................................................


[NO ISSUE] Take defensive copy of array options

Change-Id: I6085e7fc392e8bac960c478bf1500b077528c4ea
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2451
Sonar-Qube: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
Contrib: Jenkins <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Murtadha Hubail <[email protected]>
---
M 
hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/config/ConfigManager.java
1 file changed, 13 insertions(+), 1 deletion(-)

Approvals:
  Anon. E. Moose #1000171: 
  Jenkins: Verified; No violations found; ; Verified
  Murtadha Hubail: Looks good to me, approved



diff --git 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/config/ConfigManager.java
 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/config/ConfigManager.java
index baff800..9564922 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/config/ConfigManager.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/config/ConfigManager.java
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.lang.reflect.Array;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -40,6 +41,7 @@
 import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 import org.apache.commons.collections4.map.CompositeMap;
@@ -491,7 +493,17 @@
     }
 
     public void set(String nodeId, IOption option, Object value) {
-        invokeSetters(option, value, nodeId);
+        invokeSetters(option, copyIfArray(value), nodeId);
+    }
+
+    private Object copyIfArray(Object orig) {
+        if (orig == null || !orig.getClass().isArray()) {
+            return orig;
+        }
+        int arrayLength = Array.getLength(orig);
+        Object copy = Array.newInstance(orig.getClass().getComponentType(), 
arrayLength);
+        IntStream.range(0, arrayLength).forEach(i -> Array.set(copy, i, 
Array.get(orig, i)));
+        return copy;
     }
 
     public Object get(IOption option) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2451
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6085e7fc392e8bac960c478bf1500b077528c4ea
Gerrit-PatchSet: 2
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <[email protected]>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Michael Blow <[email protected]>
Gerrit-Reviewer: Murtadha Hubail <[email protected]>

Reply via email to