Object_MonitorOwner requires a Thread to be the owner of an Object before calling notify() or wait() on this Object. This property would trigger violations by detecting if Threads.holdsLock(o) is true when calling notify(o) wait(o), which is the condition that JVM will throw an IllegalMonitorStateException. The violations triggered by this property do not provide more useful debugging information than the exception from JVM, nor do they provide any insight into the prevention of the exception. We'd suggest to remove this property.
The snippet below presents the condition described by this property that JavaMOP would trigger a violation.
Compile and execute the program below with JDK 1.6-1.8, IllegalMonitorStateException would be thrown at "o.notify();",
where current thread is not Thread t which holds Object o.
public class Test {
public static void main(String[] args) throws Exception {
final Object o = new Object();
Thread t = new Thread() {
@Override
public void run() {
synchronized(o) {
while(true);
}
}
};
Thread.currentThread().sleep(1000);
o.notify();
}
Object_MonitorOwner requires a Thread to be the owner of an Object before calling notify() or wait() on this Object. This property would trigger violations by detecting if Threads.holdsLock(o) is true when calling notify(o) wait(o), which is the condition that JVM will throw an IllegalMonitorStateException. The violations triggered by this property do not provide more useful debugging information than the exception from JVM, nor do they provide any insight into the prevention of the exception. We'd suggest to remove this property. The snippet below presents the condition described by this property that JavaMOP would trigger a violation. Compile and execute the program below with JDK 1.6-1.8, IllegalMonitorStateException would be thrown at "o.notify();", where current thread is not Thread t which holds Object o.
public class Test { public static void main(String[] args) throws Exception { final Object o = new Object(); Thread t = new Thread() { @Override public void run() { synchronized(o) {
while(true); } } }; Thread.currentThread().sleep(1000); o.notify(); }