如何正确调用method()
from 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'