[ nice-Bugs-1090881 ] IllegalMonitorStateException

"SourceForge.net" <[email protected]> Tue, 28 Dec 2004 07:41:15 -0800
Newsgroups gmane.comp.lang.nice.devel
Message-ID <[email protected]>
Bugs item #1090881, was opened at 2004-12-24 17:11
Message generated for change (Comment added) made by arjanb
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1090881&group_id=12788

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Artem Gr Kozarezov (artemgr)
Assigned to: Nobody/Anonymous (nobody)
Summary: IllegalMonitorStateException

Initial Comment:
The following program:

void main( String[] ){
  List<Integer> list = new LinkedList();
  int n = 9;
  while( 0 != --n ) list.add( new Integer( n ) );
  while( true ){
    synchronized( list ){
      if( list.isEmpty() ) break;
      list.removeAt( 0 );
    }
  }
  println( "OK" );
}

prints

OK
Exception in thread "main"
java.lang.IllegalMonitorStateException
        at sync.fun.main(sync.nice:9)
        at sync.dispatch.main(dispatch.nice)

It's strange also to see "OK". In real application the
thread of control was interrupted (jumped to the
appropriate catch block).

It is possible to workaround this bug, by moving
"break" outside of the "synchronized" block.

nicec --version
Nice compiler version 0.9.10 prerelease (build
2004.12.07, 13:42:26 UTC)
Compiled using JDK 1.4.2-01

java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

The similar Java program (see below) works without
exceptions:

import java.util.*;
public class test {
  public static void main( String[] argv ){
    List list = new LinkedList();
    int n = 9;
    while( 0 != --n ) list.add( new Integer( n ) );
    while( true ){
      synchronized( list ){
        if( list.isEmpty() ) break;
        list.remove( 0 );
      }
    }
    System.out.println( "OK" );
  }
}


----------------------------------------------------------------------

>Comment By: Arjan Boeijink (arjanb)
Date: 2004-12-28 16:41

Message:
Logged In: YES 
user_id=688815

'continue' has the same problem.

----------------------------------------------------------------------

Comment By: Artem Gr Kozarezov (artemgr)
Date: 2004-12-24 18:23

Message:
Logged In: YES 
user_id=289741

What about "continue"? Is it safe to use?

----------------------------------------------------------------------

Comment By: Arjan Boeijink (arjanb)
Date: 2004-12-24 17:21

Message:
Logged In: YES 
user_id=688815

This is a known bug in the codegenerator.
It doesn't handle breaking out a try-finally or synchronized 
block correctly.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1090881&group_id=12788


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/