refactor: ConcurrentMap usage must be fixed
- Dominant language
- Java
- Stars
- 2.4k
- Forks
- 940
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 160
Description
Problem code example:
``` java
public boolean updateDeck(UUID playerId, Deck deck) {
if (tournamentSessions.containsKey(playerId)) {
return tournamentSessions.get(playerId).updateDeck(deck);
}
return false;
}
```
It can generate NPE errors cause `containsKey` and `get` are two different commands and processing in diff time (e.g. after key/value removed in other thread):
```
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)
at mage.server.tournament.TournamentController.updateDeck(TournamentController.java:328)
at mage.server.tournament.TournamentManagerImpl.updateDeck(TournamentManagerImpl.java:65)
```
I don't think it require details research and steps to reproduce. Just use an improved code like:
```
val = concurrentMap.getOrDefault(key, null);
if (val != null) then
```
~20 fields usages to check:

Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.