org.sonar.l10n.java.rules.squid.S2222.html Maven / Gradle / Ivy
The logic in a method should ensure that locks are released in the methods in which they were acquired. Failure to release a lock increases the potential for deadlocks and could result in runtime errors in production.
Noncompliant Code Example
public class MyClass {
Lock lock = new Lock();
public void acquireLock() {
lock.lock(); // Noncompliant;
}
public void releaseLock() {
lock.unlock();
}
public void doTheThing() {
acquireLock();
// do work...
releaseLock();
}
}
Compliant Solution
public class MyClass {
Lock lock = new Lock();
public void doTheThing() {
lock.lock();
// do work...
lock.unlock();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy