Skip to content

Commit 2a3b3af

Browse files
committed
Ensure sets maintain insertion order
1 parent e56fbb0 commit 2a3b3af

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import java.io.Closeable;
2626
import java.time.Duration;
2727
import java.time.Instant;
28+
import java.util.Collections;
2829
import java.util.Deque;
2930
import java.util.Iterator;
31+
import java.util.LinkedHashSet;
3032
import java.util.List;
3133
import java.util.Map;
3234
import java.util.Optional;
@@ -178,7 +180,10 @@ private void timeoutSessions() {
178180
sessionRequest.getRequestId().equals(entry.getKey())))
179181
.filter(entry -> isTimedOut(now, entry.getValue()))
180182
.map(Map.Entry::getKey)
181-
.collect(Collectors.toSet());
183+
.collect(
184+
Collectors.collectingAndThen(
185+
Collectors.toCollection(LinkedHashSet::new),
186+
set -> Collections.unmodifiableSet(new LinkedHashSet<>(set))));
182187
} finally {
183188
readLock.unlock();
184189
}

java/src/org/openqa/selenium/grid/web/JarFileResource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.io.UncheckedIOException;
24+
import java.util.Collections;
25+
import java.util.LinkedHashSet;
2426
import java.util.Optional;
2527
import java.util.Set;
2628
import java.util.jar.JarFile;
@@ -100,7 +102,10 @@ public Set<Resource> list() {
100102
.filter(e -> !e.getName().equals(prefix))
101103
.filter(e -> e.getName().split("/").length == count)
102104
.map(e -> new JarFileResource(jarFile, e.getName(), prefix))
103-
.collect(Collectors.toUnmodifiableSet());
105+
.collect(
106+
Collectors.collectingAndThen(
107+
Collectors.toCollection(LinkedHashSet::new),
108+
set -> Collections.unmodifiableSet(new LinkedHashSet<>(set))));
104109
}
105110

106111
@Override

java/src/org/openqa/selenium/grid/web/MergedResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Collections;
2121
import java.util.HashSet;
22+
import java.util.LinkedHashSet;
2223
import java.util.Optional;
2324
import java.util.Set;
2425
import org.openqa.selenium.internal.Require;
@@ -67,9 +68,9 @@ public boolean isDirectory() {
6768

6869
@Override
6970
public Set<Resource> list() {
70-
Set<Resource> resources = new HashSet<>(base.list());
71+
Set<Resource> resources = new LinkedHashSet<>(base.list());
7172
next.ifPresent(res -> resources.addAll(res.list()));
72-
return Collections.unmodifiableSet(resources);
73+
return Collections.unmodifiableSet(new LinkedHashSet<>(resources));
7374
}
7475

7576
@Override

java/src/org/openqa/selenium/grid/web/PathResource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
2424
import java.util.Arrays;
25+
import java.util.Collections;
26+
import java.util.LinkedHashSet;
2527
import java.util.Optional;
2628
import java.util.Set;
2729
import java.util.function.Predicate;
@@ -88,7 +90,10 @@ public Set<Resource> list() {
8890
return files
8991
.filter(allowedSubpaths)
9092
.map(PathResource::new)
91-
.collect(Collectors.toUnmodifiableSet());
93+
.collect(
94+
Collectors.collectingAndThen(
95+
Collectors.toCollection(LinkedHashSet::new),
96+
set -> Collections.unmodifiableSet(new LinkedHashSet<>(set))));
9297
} catch (IOException e) {
9398
throw new UncheckedIOException(e);
9499
}

0 commit comments

Comments
 (0)