This was very hard to discover, but it is real and easy to reproduce. Try running this program:

var finalies = 1
var line = 'TEST THIS LINE'
try {
 while ('' !== (line = line.substring(0, line.length - 1))) {
  if (line.length % 2 == 0) {
   continue
  }
  java.lang.System.out.println(line)
 }
}
catch (x) {
  java.lang.System.out.println(x)
}
finally {
 java.lang.System.out.println('Finalies ' + (finalies++))
}

If you run this code, you'll see that the "finally" block is run every time "continue" is reached, and then the while loop continues after the "finally" block is run. Of course, the "finally" block should only be called once in this example, and the while loop should not continue, and this broken behavior can lead to serious problems.

(I added the "catch" block only to make sure that exceptions are not thrown, and indeed they are not. Sorry about the silly functionality of the program, but it's the result of trying to wrap my head around what was going on...)

Or maybe I'm crazy and am missing something trivial? The same code runs in Rhino without this problem.

The bug appears in the 8u40 release. :(

-Tal

Reply via email to