Skip to content

Commit fb29088

Browse files
committed
Revise LinkedCaseInsensitiveMap's lazy key/value/entry collections
Closes gh-22926
1 parent 82d32f0 commit fb29088

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
5656
private final Locale locale;
5757

5858
@Nullable
59-
private transient Set<String> keySet;
59+
private transient volatile Set<String> keySet;
6060

6161
@Nullable
62-
private transient Collection<V> values;
62+
private transient volatile Collection<V> values;
6363

6464
@Nullable
65-
private transient Set<Entry<String, V>> entrySet;
65+
private transient volatile Set<Entry<String, V>> entrySet;
6666

6767

6868
/**
@@ -465,7 +465,7 @@ public void forEach(Consumer<? super Entry<String, V>> action) {
465465
}
466466

467467

468-
private class EntryIterator {
468+
private abstract class EntryIterator<T> implements Iterator<T> {
469469

470470
private final Iterator<Entry<String, V>> delegate;
471471

@@ -476,16 +476,18 @@ public EntryIterator() {
476476
this.delegate = targetMap.entrySet().iterator();
477477
}
478478

479-
public Entry<String, V> nextEntry() {
479+
protected Entry<String, V> nextEntry() {
480480
Entry<String, V> entry = this.delegate.next();
481481
this.last = entry;
482482
return entry;
483483
}
484484

485+
@Override
485486
public boolean hasNext() {
486487
return this.delegate.hasNext();
487488
}
488489

490+
@Override
489491
public void remove() {
490492
this.delegate.remove();
491493
if (this.last != null) {
@@ -496,7 +498,7 @@ public void remove() {
496498
}
497499

498500

499-
private class KeySetIterator extends EntryIterator implements Iterator<String> {
501+
private class KeySetIterator extends EntryIterator<String> {
500502

501503
@Override
502504
public String next() {
@@ -505,7 +507,7 @@ public String next() {
505507
}
506508

507509

508-
private class ValuesIterator extends EntryIterator implements Iterator<V> {
510+
private class ValuesIterator extends EntryIterator<V> {
509511

510512
@Override
511513
public V next() {
@@ -514,7 +516,7 @@ public V next() {
514516
}
515517

516518

517-
private class EntrySetIterator extends EntryIterator implements Iterator<Entry<String, V>> {
519+
private class EntrySetIterator extends EntryIterator<Entry<String, V>> {
518520

519521
@Override
520522
public Entry<String, V> next() {

0 commit comments

Comments
 (0)