Skip to content

Commit

Permalink
synchronized entrySet/values creation
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyy-dev committed Nov 28, 2021
1 parent 47f955e commit 09d0cf1
Showing 1 changed file with 14 additions and 4 deletions.
Expand Up @@ -89,8 +89,8 @@ private static int offset(final TextDecoration decoration) {
private final int bitSet;

// lazy
private EntrySet entrySet = null;
private Values values = null;
private volatile EntrySet entrySet = null;
private volatile Values values = null;

private DecorationMap(final int bitSet) {
this.bitSet = bitSet;
Expand Down Expand Up @@ -139,7 +139,12 @@ public boolean isEmpty() {
@Override
public @NotNull Set<Entry<TextDecoration, TextDecoration.State>> entrySet() {
if (this.entrySet == null) {
this.entrySet = new EntrySet();
synchronized (this) {
// re-check for lost race condition
if (this.entrySet == null) {
this.entrySet = new EntrySet();
}
}
}
return this.entrySet;
}
Expand All @@ -152,7 +157,12 @@ public boolean isEmpty() {
@Override
public @NotNull Collection<TextDecoration.State> values() {
if (this.values == null) {
this.values = new Values();
synchronized (this) {
// re-check for lost race condition
if (this.values == null) {
this.values = new Values();
}
}
}
return this.values;
}
Expand Down

0 comments on commit 09d0cf1

Please sign in to comment.