• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • DSO:L1
  • drb
  • Reporter: teck
  • March 21, 2007
  • 0
  • Watchers: 0
  • July 27, 2012
  • March 22, 2007

Description

I actually don’t know what is wrong yet, but running this code where “array” is a managed array, you’ll get an IllegalMonitorStateException.

String[] array = new String[5]; 

try {
  for (int i = 0; i < 10; i++) {
    System.err.println(i + ": " + array[i]);
  }
} catch (ArrayIndexOutOfBoundsException ia) {
  System.err.println("caught exception");
}

Comments

Tim Eck 2007-03-21

This appears to be the VM checking the balance of lock acquires/releases made a thread within the context of method invocation

We are causing a violation to rule (1) from the VM spec (http://java.sun.com/docs/books/jvms/second_edition/html/Threads.doc.html#22500):

Implementations of the Java virtual machine are permitted but not required to enforce both of the following two rules guaranteeing structured locking.

Let T be a thread and L be a lock. Then:

  1. The number of lock operations performed by T on L during a method invocation must equal the number of unlock operations performed by T on L during the method invocation whether the method invocation completes normally or abruptly.

  2. At no point during a method invocation may the number of unlock operations performed by T on L since the method invocation exceed the number of lock operations performed by T on L since the method invocation.