Skip to content

Instantly share code, notes, and snippets.

@emopers
Last active April 1, 2016 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emopers/734334314617a787e398 to your computer and use it in GitHub Desktop.
Save emopers/734334314617a787e398 to your computer and use it in GitHub Desktop.
##Unncessary property##
Object_MonitorOwner (https://goo.gl/5Ek4FX) 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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment