Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fix NameSimilarityCheck ConcurrentModificationException.
Browse files Browse the repository at this point in the history
  • Loading branch information
awumii committed Sep 5, 2021
1 parent 8c6dde5 commit b46f436
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

@SuppressWarnings("UnstableApiUsage")
public class NameSimilarityCheck extends Check {
private final Queue<String> nameHistory =
EvictingQueue.create(this.epicGuard.config().nameSimilarityCheck().historySize());
private final Queue<String> nameHistory = EvictingQueue.create(this.epicGuard.config().nameSimilarityCheck().historySize());
private final LevenshteinDistance distanceAlgorithm = LevenshteinDistance.getDefaultInstance();

public NameSimilarityCheck(EpicGuard epicGuard) {
Expand All @@ -36,19 +35,21 @@ public NameSimilarityCheck(EpicGuard epicGuard) {

@Override
public boolean handle(@NotNull ConnectingUser user) {
for (String nick : this.nameHistory) {
if (nick.equals(user.nickname())) {
return false; // ignore identical nickname.
synchronized (this.nameHistory) {
for (String nick : this.nameHistory) {
if (nick.equals(user.nickname())) {
return false; // ignore identical nickname.
}

int distance = this.distanceAlgorithm.apply(nick, user.nickname());
if (distance <= this.epicGuard.config().nameSimilarityCheck().distance()) {
return this.evaluate(this.epicGuard.config().nameSimilarityCheck().checkMode(), true);
}
}

int distance = this.distanceAlgorithm.apply(nick, user.nickname());
if (distance <= this.epicGuard.config().nameSimilarityCheck().distance()) {
return this.evaluate(this.epicGuard.config().nameSimilarityCheck().checkMode(), true);
}
this.nameHistory.add(user.nickname());
return false;
}

this.nameHistory.add(user.nickname());
return false;
}

@Override
Expand Down

0 comments on commit b46f436

Please sign in to comment.