mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-26 19:15:09 +00:00
Fix PackedMap entry equality and hash codes (#27396)
This commit is contained in:
1 parent
ec61ae721e
commit
b4488dc4bf
2 files changed
+15
-16
No files matched your search
@@ -92,22 +92,7 @@ public final class PackedMap<K, V> extends AbstractMap<K, V> {
|
||||
public Entry<K, V> next() {
|
||||
final K k = (K) kvpairs[index++];
|
||||
final V v = (V) kvpairs[index++];
|
||||
return new Entry<>() {
|
||||
@Override
|
||||
public K getKey() {
|
||||
return k;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
return new SimpleImmutableEntry<>(k, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package hudson.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -55,6 +56,19 @@ class PackedMapTest {
|
||||
xs.fromXML(xml);
|
||||
}
|
||||
|
||||
@Test
|
||||
void entryEqualityAndHashCode() {
|
||||
Map<String, String> source = Map.of("a", "b", "c", "d");
|
||||
PackedMap<String, String> packed = PackedMap.of(source);
|
||||
|
||||
assertEquals(source.entrySet(), packed.entrySet());
|
||||
assertEquals(packed.entrySet(), source.entrySet());
|
||||
assertEquals(source.hashCode(), packed.hashCode());
|
||||
assertEquals(packed.hashCode(), packed.hashCode());
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> packed.entrySet().iterator().next().setValue("changed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void values() {
|
||||
Map<String, String> o = new TreeMap<>();
|
||||
|
||||
Reference in new issue
Block a user