Skip to content

Commit 99ff348

Browse files
authored
Retain child item identity when using a NameMangler (#486)
2 parents 5338bc4 + 7cb4f33 commit 99ff348

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import static org.hamcrest.Matchers.is;
7070
import static org.hamcrest.Matchers.notNullValue;
7171
import static org.junit.Assert.assertEquals;
72+
import static org.junit.Assert.assertSame;
7273

7374

7475
/**
@@ -120,8 +121,16 @@ public void evaluate() throws Throwable {
120121
assertThat("Item loaded from disk", i, instanceOf(ComputedFolderImpl.class));
121122
instance = (ComputedFolderImpl) i;
122123
checkComputedFolder(instance, 0);
124+
var items = new ArrayList<>(instance.getItems());
123125
instance.doReload();
124126
checkComputedFolder(instance, 0);
127+
var newItems = new ArrayList<>(instance.getItems());
128+
// Check child items identity is preserved
129+
assertThat("Items are the same", items, is(newItems));
130+
for (int k = 0; k < items.size(); k++) {
131+
assertSame("Individual items must be the same", items.get(k), newItems.get(k));
132+
}
133+
125134
}
126135
});
127136
}

0 commit comments

Comments
 (0)