@Test(timeout = 1000) public void locksWillBeAutoClosed() { final AtomicInteger callCount = new AtomicInteger(0); try (final AutoCloseableReentrantLock.AutoCloseableLock ignored = new AutoCloseableReentrantLock(AutoCloseableReentrantLockTest.class, "user1").lock()) { callCount.incrementAndGet(); } try (final AutoCloseableReentrantLock.AutoCloseableLock ignored = new AutoCloseableReentrantLock(AutoCloseableReentrantLockTest.class, "user1").lock()) { callCount.incrementAndGet(); } assertThat(callCount.get(), is(2)); }
@SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) public AutoCloseableLock lock() throws IllegalStateException { checkNotReleased(); lock.lock(); return autoCloseable; }
AutoCloseableReentrantLock { @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) public AutoCloseableLock lock() throws IllegalStateException { checkNotReleased(); lock.lock(); return autoCloseable; } }
AutoCloseableReentrantLock { @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) public AutoCloseableLock lock() throws IllegalStateException { checkNotReleased(); lock.lock(); return autoCloseable; } AutoCloseableReentrantLock(final Class clazz, final String resource); }
AutoCloseableReentrantLock { @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) public AutoCloseableLock lock() throws IllegalStateException { checkNotReleased(); lock.lock(); return autoCloseable; } AutoCloseableReentrantLock(final Class clazz, final String resource); @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) AutoCloseableLock lock(); Optional<AutoCloseableLock> tryLock(); @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) AutoCloseableLock lockInterruptibly(); boolean isHeldByCurrentThread(); boolean isLocked(); }
AutoCloseableReentrantLock { @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) public AutoCloseableLock lock() throws IllegalStateException { checkNotReleased(); lock.lock(); return autoCloseable; } AutoCloseableReentrantLock(final Class clazz, final String resource); @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) AutoCloseableLock lock(); Optional<AutoCloseableLock> tryLock(); @SuppressWarnings( "LockAcquiredButNotSafelyReleased" ) AutoCloseableLock lockInterruptibly(); boolean isHeldByCurrentThread(); boolean isLocked();  }