Reputation: 11
The below class appears to be stuck in the method lrPoints, when used with a client provided Map. The conclusion so far is that either lrPoint is running an infinite loop or there is a deadlock. I am unable to reproduce the bug but can assure by reading the logs that the method lrPoints is never exited.
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import org.apache.commons.lang3.tuple.Pair;
import org.joda.time.LocalDateTime;
public final class TimeSeries {
private final NavigableMap<LocalDateTime, Double> series = new ConcurrentSkipListMap<>();
public TimeSeries(Map<LocalDateTime, Double> m) {
series.putAll(m);
}
public Double get(LocalDateTime t){
return series.get(t);
}
public Pair<Entry<LocalDateTime, Double>, Entry<LocalDateTime, Double>> lrPoints(LocalDateTime t) {
if (series.isEmpty() || t.isBefore(series.firstKey()) || t.isAfter(series.lastKey()))
throw new IllegalArgumentException("t outside of time series bounds");
Entry<LocalDateTime, Double> l = series.floorEntry(t);
Entry<LocalDateTime, Double> r = series.ceilingEntry(t);
return Pair.of(l,r);
}
}
Adding to the problem, the "get" method returns ok. Is this map constructed correctly to prevent client locking? Is there any other reason this method could fail?
Edit. After adding more logging and changing to TreeMap. I see now the problem is the static constructor method Pair.of(.,.). Is there a reason such static initialiser could cause a deadlock?
Upvotes: 0
Views: 145