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

ibessonov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 89674e022c IGNITE-18601 Copy configuration tree when adding default 
values (#1570)
89674e022c is described below

commit 89674e022c7c3e9e2507c200f43615ddc441cde8
Author: Alexander Polovtcev <[email protected]>
AuthorDate: Wed Jan 25 09:30:35 2023 +0200

    IGNITE-18601 Copy configuration tree when adding default values (#1570)
---
 .../configuration/util/ConfigurationUtil.java      | 13 ++++++-------
 .../configuration/util/ConfigurationUtilTest.java  | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git 
a/modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java
 
b/modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java
index f050af139d..e17c908043 100644
--- 
a/modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java
+++ 
b/modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java
@@ -321,14 +321,10 @@ public class ConfigurationUtil {
             /** {@inheritDoc} */
             @Override
             public Object visitInnerNode(String key, InnerNode innerNode) {
-                InnerNode childNode = node.traverseChild(key, 
innerNodeVisitor(), true);
-
-                // Instantiate field in destination node before doing 
something else.
-                if (childNode == null) {
-                    node.construct(key, EMPTY_CFG_SRC, true);
+                // Copy or create the element.
+                node.construct(key, EMPTY_CFG_SRC, true);
 
-                    childNode = node.traverseChild(key, innerNodeVisitor(), 
true);
-                }
+                InnerNode childNode = node.traverseChild(key, 
innerNodeVisitor(), true);
 
                 addDefaults(childNode);
 
@@ -338,6 +334,9 @@ public class ConfigurationUtil {
             /** {@inheritDoc} */
             @Override
             public Object visitNamedListNode(String key, NamedListNode<?> 
namedList) {
+                // Copy or create the element.
+                node.construct(key, EMPTY_CFG_SRC, true);
+
                 namedList = node.traverseChild(key, namedListNodeVisitor(), 
true);
 
                 for (String namedListKey : namedList.namedListKeys()) {
diff --git 
a/modules/configuration/src/test/java/org/apache/ignite/internal/configuration/util/ConfigurationUtilTest.java
 
b/modules/configuration/src/test/java/org/apache/ignite/internal/configuration/util/ConfigurationUtilTest.java
index 0ce48e6b72..ef36ae4bb1 100644
--- 
a/modules/configuration/src/test/java/org/apache/ignite/internal/configuration/util/ConfigurationUtilTest.java
+++ 
b/modules/configuration/src/test/java/org/apache/ignite/internal/configuration/util/ConfigurationUtilTest.java
@@ -45,6 +45,7 @@ import static org.hamcrest.Matchers.matchesPattern;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -59,6 +60,7 @@ import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.UUID;
 import java.util.function.Consumer;
+import org.apache.ignite.configuration.NamedListView;
 import org.apache.ignite.configuration.RootKey;
 import org.apache.ignite.configuration.annotation.Config;
 import org.apache.ignite.configuration.annotation.ConfigValue;
@@ -808,6 +810,26 @@ public class ConfigurationUtilTest {
         assertEquals(List.of("0"), removeLastKey(List.of("0", "1")));
     }
 
+    /**
+     * Tests that {@link ConfigurationUtil#addDefaults} copies the tree when 
adding default values.
+     */
+    @Test
+    void testAddDefaultsPurity() {
+        InnerNode parentNode = 
newNodeInstance(ParentConfigurationSchema.class);
+
+        ParentChange parentChange = (ParentChange) parentNode;
+
+        parentChange.changeElements(elements -> elements.create("name", 
element -> {}));
+
+        NamedListView<?> beforeDefaults = parentChange.elements();
+
+        addDefaults(parentNode);
+
+        NamedListView<?> afterDefaults = parentChange.elements();
+
+        assertNotSame(afterDefaults, beforeDefaults);
+    }
+
     /**
      * Patches super root and returns flat representation of the changes. 
Passed {@code superRoot} object will contain patched tree when
      * method execution is completed.

Reply via email to