Skip to content

Commit 1c7d728

Browse files
committed
Retain child item identity when using a NameMangler
PR #376 caused every child to be recreated on reload, whereas the intent is to retain the object identity.
1 parent 5338bc4 commit 1c7d728

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ public static <K, V extends TopLevelItem> Map<K, V> loadChildren(AbstractFolder<
365365
V itemFromDir;
366366
V item;
367367
String name;
368-
item = itemFromDir = byDirName.get(childName);
369368
var legacyName = subdir.getName();
369+
item = itemFromDir = byDirName.get(legacyName);
370370
try {
371371
if (item == null) {
372372
XmlFile xmlFile = Items.getConfigFile(subdir);

src/test/java/com/cloudbees/hudson/plugins/folder/ChildNameGeneratorAltTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.ArrayList;
5050
import java.util.Arrays;
5151
import java.util.Collection;
52+
import java.util.Collections;
5253
import java.util.List;
5354
import java.util.Locale;
5455
import java.util.Set;
@@ -69,6 +70,7 @@
6970
import static org.hamcrest.Matchers.is;
7071
import static org.hamcrest.Matchers.notNullValue;
7172
import static org.junit.Assert.assertEquals;
73+
import static org.junit.Assert.assertSame;
7274

7375

7476
/**
@@ -120,8 +122,16 @@ public void evaluate() throws Throwable {
120122
assertThat("Item loaded from disk", i, instanceOf(ComputedFolderImpl.class));
121123
instance = (ComputedFolderImpl) i;
122124
checkComputedFolder(instance, 0);
125+
var items = new ArrayList<>(instance.getItems());
123126
instance.doReload();
124127
checkComputedFolder(instance, 0);
128+
var newItems = new ArrayList<>(instance.getItems());
129+
// Check child items identity is preserved
130+
assertThat("Items are the same", items, is(newItems));
131+
for (int k = 0; k < items.size(); k++) {
132+
assertSame("Individual items must be the same", items.get(k), newItems.get(k));
133+
}
134+
125135
}
126136
});
127137
}

0 commit comments

Comments
 (0)