Skip to content

Commit 215f828

Browse files
committed
Fix potential deadlocks
1 parent 94ece59 commit 215f828

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

src/main/java/org/gephi/graph/impl/TimeIndexStore.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ public void add(K k, Element element) {
102102
if (!viewIndexes.isEmpty()) {
103103
for (Entry<GraphView, TimeIndexImpl> entry : viewIndexes.entrySet()) {
104104
GraphViewImpl graphView = (GraphViewImpl) entry.getKey();
105-
DirectedSubgraph graph = graphView.getDirectedGraph();
106105
boolean node = element instanceof Node;
107-
if (node ? graph.contains((Node) element) : graph.contains((Edge) element)) {
106+
if (node ? graphView.containsNode((Node) element) : graphView.containsEdge((Edge) element)) {
108107
entry.getValue().add(timeIndex, element);
109108
}
110109
}
@@ -201,46 +200,42 @@ public boolean contains(K k) {
201200
}
202201

203202
public void index(Element element) {
204-
lock();
205-
try {
203+
synchronized (element) {
206204
S timeSet = getTimeSet(element);
207-
208-
if (timeSet != null) {
209-
add(timeSet, element);
210-
}
211-
212-
synchronized (element) {
205+
lock();
206+
try {
207+
if (timeSet != null) {
208+
add(timeSet, element);
209+
}
213210
for (Object val : element.getAttributes()) {
214211
if (val instanceof TimeMap) {
215212
TimeMap dynamicValue = (TimeMap) val;
216213
add(dynamicValue);
217214
}
218215
}
216+
} finally {
217+
unlock();
219218
}
220-
} finally {
221-
unlock();
222219
}
223220
}
224221

225222
public void clear(Element element) {
226-
lock();
227-
try {
223+
synchronized (element) {
228224
S timeSet = getTimeSet(element);
229-
230-
if (timeSet != null) {
231-
remove(timeSet, element);
232-
}
233-
234-
synchronized (element) {
225+
lock();
226+
try {
227+
if (timeSet != null) {
228+
remove(timeSet, element);
229+
}
235230
for (Object val : element.getAttributes()) {
236231
if (val instanceof TimeMap) {
237232
TimeMap dynamicValue = (TimeMap) val;
238233
remove((M) dynamicValue);
239234
}
240235
}
236+
} finally {
237+
unlock();
241238
}
242-
} finally {
243-
unlock();
244239
}
245240
}
246241

@@ -454,7 +449,7 @@ public boolean deepEquals(TimeIndexStore obj) {
454449
if (!obj.getClass().equals(getClass())) {
455450
return false;
456451
}
457-
TimeIndexStore other = (TimeIndexStore) obj;
452+
TimeIndexStore other = obj;
458453
if (!other.elementType.equals(elementType)) {
459454
return false;
460455
}

0 commit comments

Comments
 (0)