diff --git a/core/src/com/google/inject/internal/CycleDetectingLock.java b/core/src/com/google/inject/internal/CycleDetectingLock.java index d767015548..c3710a63a6 100644 --- a/core/src/com/google/inject/internal/CycleDetectingLock.java +++ b/core/src/com/google/inject/internal/CycleDetectingLock.java @@ -249,6 +249,9 @@ private ListMultimap detectPotentialLocksCycle() { MultimapBuilder.linkedHashKeys().arrayListValues().build(); // lock that is a part of a potential locks cycle, starts with current lock ReentrantCycleDetectingLock lockOwnerWaitingOn = this; + // Its possible the lock owner thread has not removed itself yet from the waiting-on-lock list. + // So we remove it here, to prevent an endless loop. See #1510. + lockThreadIsWaitingOn.remove(lockOwnerWaitingOn.lockOwnerThread); // try to find a dependency path between lock's owner thread and a current thread while (lockOwnerWaitingOn != null && lockOwnerWaitingOn.lockOwnerThread != null) { Thread threadOwnerThreadWaits = lockOwnerWaitingOn.lockOwnerThread;