Skip to content

Commit

Permalink
[Truffle] Fix bugs in RopeTable#getRope(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Apr 10, 2016
1 parent 0b6169c commit d166ef9
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public Rope getRope(String string) {
if (key != null) {
final WeakReference<Rope> ropeReference = ropesTable.get(key);

if (ropeReference != null) {
if (ropeReference != null && ropeReference.get() != null) {
return ropeReference.get();

This comment has been minimized.

Copy link
@eregon

eregon Apr 11, 2016

Member

In the worst case, it looks like the reference could be collected between these 2 get().

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Apr 11, 2016

Author Contributor

Ah yes of course - thanks.

}
}
@@ -69,12 +69,12 @@ public Rope getRope(String string) {

WeakReference<Rope> ropeReference = ropesTable.get(key);

if (ropeReference == null) {
if (ropeReference == null || ropeReference.get() == null) {
ropeReference = new WeakReference<>(rope);
ropesTable.put(key, ropeReference);
}

return ropeReference.get();
return rope;
} finally {
lock.writeLock().unlock();
}

0 comments on commit d166ef9

Please sign in to comment.