- SonarQube 7.7.0.23042
- SonarJava 5.11.0.17289 (java)
The Lombok annotation @Cleanup
triggers 2 false positives: squid:S1854
and squid:S1481
import lombok.Cleanup;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
public class CleanupTest {
private Map<String, ReentrantLock> lockCache = new ConcurrentHashMap<>();
private ReentrantLock getLock(String name) {
ReentrantLock lock = lockCache.computeIfAbsent(name, s -> new ReentrantLock());
lock.lock();
return lock;
}
public void testCleanupLombok() {
@Cleanup("unlock") ReentrantLock lock = getLock("foo");
System.out.println("Do something");
}
public void testCleanupDeLomboked() {
ReentrantLock lock = getLock("foo");
try {
System.out.println("Do something");
} finally {
if (java.util.Collections.singletonList(lock).get(0) != null) {
lock.unlock();
}
}
}
}