Cześć. Zaczynam trochę szkrobać w Javie. Po raz pierwszy używam struktury danych ConcurrentHashMap. Tutaj mniej więcej mój kod:
private Player target; // zostaje później zainicjalizowany, na pewno, sprawdzałem na każdy możliwy sposób
private ConcurrentHashMap<Integer, Long> effects_ends = new ConcurrentHashMap<Integer, Long>();
...
if(this.effects.isEmpty() || duration==0 || max_effects==0 || this.target==null) { //null check na this.target
player.sendMessage("first check progress");
this.remove();
return;
}
int target_hash = this.target.hashCode();
// tu był println ( dotąd wypisywało )
if ((!affect_before_end) && (effects_ends.containsKey(target_hash))) {
// tu był println
if ((Instant.now().toEpochMilli() - effects_ends.get(target_hash) < this.duration * 20)) {
// tu był println
this.remove();
return;
} else effects_ends.remove(target_hash);
}
// tu był println
Dostaję NPE w containsKey (wiem, bo robiłem mnóstwo println i wychodzi na to, że właśnie ten check wywala NPE), jednak nie mam zielonego pojęcia dlaczego. Null check jest.