Как правильно позвонить method()
из main(..)
?
class LockCheckerTest {
static class Y {
final Lock z = new ReentrantLock(true);
}
private final static Date x = new Date((long) (System.currentTimeMillis() * Math.random()));
private final static Y y = new Y();
@Holding({"x", "y.z"})
@ReleasesNoLocks
static void method() {
System.out.println(x);
}
public static void main(String[] args) {
synchronized (x) { // acquire intrinsic lock of 'x'
synchronized (y) { // locking 'y' is not required, just trying to compile
y.z.lock(); // acquire explicit lock 'y.z'
method(); // ERROR
y.z.unlock();
}
}
}
}
Ошибка: (37, 23) java: [contracts.precondition.not.satisfied] незащищенный вызов метода 'method()', требующий удержания 'Holding.yz'