Skip to content

Commit 11cc34e

Browse files
committed
Fix collection-to-set conversion causing type mismatch in JCasC setters
1 parent eaed8d4 commit 11cc34e

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

plugin/src/main/java/io/jenkins/plugins/casc/BaseConfigurator.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
import java.util.Collections;
3030
import java.util.HashMap;
3131
import java.util.HashSet;
32+
import java.util.LinkedHashSet;
3233
import java.util.List;
3334
import java.util.Map;
3435
import java.util.Set;
36+
import java.util.SortedSet;
37+
import java.util.TreeSet;
3538
import java.util.logging.Level;
3639
import java.util.logging.Logger;
3740
import java.util.stream.Collectors;
@@ -169,14 +172,23 @@ public abstract class BaseConfigurator<T> implements Configurator<T> {
169172
rawAttribute.setter((targetInstance, value) -> {
170173
Object finalValue = value;
171174

172-
if (value instanceof Collection<?> collection && finalType.rawType.isArray()) {
173-
Object array = newInstance(rawAttribute.getType(), collection.size());
174-
int i = 0;
175-
for (Object item : collection) {
176-
set(array, i++, item);
175+
if (value instanceof Collection<?> collection) {
176+
if (finalType.rawType.isArray()) {
177+
Object array = newInstance(rawAttribute.getType(), collection.size());
178+
int i = 0;
179+
for (Object item : collection) {
180+
set(array, i++, item);
181+
}
182+
finalValue = array;
183+
184+
} else if (SortedSet.class.isAssignableFrom(finalType.rawType)) {
185+
finalValue = new TreeSet<>(collection);
186+
187+
} else if (Set.class.isAssignableFrom(finalType.rawType)) {
188+
finalValue = new LinkedHashSet<>(collection);
177189
}
178-
finalValue = array;
179190
}
191+
180192
bestMethod.invoke(targetInstance, finalValue);
181193
});
182194

0 commit comments

Comments
 (0)