- Sonar version 7.9.1 (build 27448)
- error observed (wrap logs/code around triple quote ``` for proper formatting)
- Paste code and run analysis with default profile for java
public static void main(String[] args) throws Exception {
Callable<Void> job = () -> {
return null;
};
executeWithLock(job, new ReentrantReadWriteLock().readLock(), "");
}
private static <V> V executeWithLock(Callable<V> operation, Lock lock, String errMsg) throws Exception {
if (lock.tryLock()) {
try {
return operation.call();
} finally {
lock.unlock();
}
} else {
throw new ConflictingOperationInProgressException(errMsg);
}
}
In fact, here is used a common pattern for lock, which is described in tryLock() javadoc:
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Lock.html#tryLock()