Skip to content
This repository was archived by the owner on Sep 14, 2026. It is now read-only.

Commit 512574e

Browse files
Bump Gradle quality stack dependencies
Includes the Dependabot quality-stack update, rebased on current main, plus a SpotBugs-compatible private lock in ChatHistoryStore.
1 parent 69c9fa4 commit 512574e

2 files changed

Lines changed: 38 additions & 29 deletions

File tree

gradle/libs.versions.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[versions]
2-
awaitility = "4.2.1"
2+
awaitility = "4.3.0"
33
checkstyle = "10.12.5"
44
jackson = "2.17.2"
55
jacoco = "0.8.12"
6-
junit = "5.10.2"
7-
junit-platform = "1.10.2"
8-
spotbugs = "6.0.12"
9-
spotbugs-annotations = "4.8.6"
6+
junit = "6.1.0"
7+
junit-platform = "6.1.0"
8+
spotbugs = "6.5.6"
9+
spotbugs-annotations = "4.10.2"
1010
spotless = "6.25.0"
1111

1212
[libraries]

src/main/java/dev/krotname/networkchat/network/ChatHistoryStore.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class ChatHistoryStore {
2424
private final Path historyFile;
2525
private final int historyLimit;
2626
private final List<ChatMessage> messages = new ArrayList<>();
27+
private final Object lock = new Object();
2728
private final boolean enabled;
2829
private int corruptRecordCount;
2930

@@ -45,41 +46,49 @@ public static ChatHistoryStore open(Path historyFile, int historyLimit) {
4546
return new ChatHistoryStore(historyFile, historyLimit, true);
4647
}
4748

48-
public synchronized void save(ChatMessage message) {
49-
if (!enabled || !isPersistable(message)) {
50-
return;
49+
public void save(ChatMessage message) {
50+
synchronized (lock) {
51+
if (!enabled || !isPersistable(message)) {
52+
return;
53+
}
54+
messages.add(message);
55+
trimToLimit();
56+
rewrite();
5157
}
52-
messages.add(message);
53-
trimToLimit();
54-
rewrite();
5558
}
5659

57-
public synchronized List<ChatMessage> recentRoomMessages(String roomName, int limit) {
58-
if (limit <= 0) {
59-
return List.of();
60-
}
61-
List<ChatMessage> roomMessages = new ArrayList<>();
62-
for (ChatMessage message : messages) {
63-
if (message.type() == MessageType.ROOM_TEXT && roomName.equals(message.room())) {
64-
roomMessages.add(message);
60+
public List<ChatMessage> recentRoomMessages(String roomName, int limit) {
61+
synchronized (lock) {
62+
if (limit <= 0) {
63+
return List.of();
6564
}
65+
List<ChatMessage> roomMessages = new ArrayList<>();
66+
for (ChatMessage message : messages) {
67+
if (message.type() == MessageType.ROOM_TEXT && roomName.equals(message.room())) {
68+
roomMessages.add(message);
69+
}
70+
}
71+
return last(roomMessages, limit);
6672
}
67-
return last(roomMessages, limit);
6873
}
6974

70-
public synchronized Set<String> knownRooms() {
71-
Set<String> rooms = new TreeSet<>();
72-
rooms.add(ChatMessage.GENERAL_ROOM);
73-
for (ChatMessage message : messages) {
74-
if (message.room() != null && !message.room().isBlank()) {
75-
rooms.add(message.room());
75+
public Set<String> knownRooms() {
76+
synchronized (lock) {
77+
Set<String> rooms = new TreeSet<>();
78+
rooms.add(ChatMessage.GENERAL_ROOM);
79+
for (ChatMessage message : messages) {
80+
if (message.room() != null && !message.room().isBlank()) {
81+
rooms.add(message.room());
82+
}
7683
}
84+
return Collections.unmodifiableSet(rooms);
7785
}
78-
return Collections.unmodifiableSet(rooms);
7986
}
8087

81-
public synchronized int corruptRecordCount() {
82-
return corruptRecordCount;
88+
public int corruptRecordCount() {
89+
synchronized (lock) {
90+
return corruptRecordCount;
91+
}
8392
}
8493

8594
private void load() {

0 commit comments

Comments
 (0)