Index: org/codehaus/janino/UnitCompiler.java =================================================================== RCS file: /cvsroot/tcljava/tcljava/src/janino/org/codehaus/janino/UnitCompiler.java,v retrieving revision 1.3 diff -u -r1.3 UnitCompiler.java --- org/codehaus/janino/UnitCompiler.java 12 May 2006 23:51:38 -0000 1.3 +++ org/codehaus/janino/UnitCompiler.java 13 May 2006 00:22:45 -0000 @@ -1301,19 +1301,18 @@ CodeContext.Offset beginningOfBody = this.codeContext.newOffset(); CodeContext.Offset afterStatement = this.codeContext.new Offset(); - // Allocate a future LV that will be used to preserve the "leave stack". - this.codeContext.saveLocalVariables(); - ts.stackValueLvIndex = this.codeContext.allocateLocalVariable((short) 2); - this.codeContext.restoreLocalVariables(); - - boolean canCompleteNormally = this.compile(ts.body); - CodeContext.Offset afterBody = this.codeContext.newOffset(); - if (canCompleteNormally) { - this.writeBranch(ts, Opcode.GOTO, afterStatement); - } + boolean canCompleteNormally = false; + // Allocate a future LV that will be used to preserve the "leave stack". this.codeContext.saveLocalVariables(); try { + ts.stackValueLvIndex = this.codeContext.allocateLocalVariable((short) 2); + + canCompleteNormally = this.compile(ts.body); + CodeContext.Offset afterBody = this.codeContext.newOffset(); + if (canCompleteNormally) { + this.writeBranch(ts, Opcode.GOTO, afterStatement); + } // Local variable for exception object. // Notice: Must be same size as "this.stackValueLvIndex". @@ -1345,7 +1344,7 @@ exceptionObjectLvIndex // localVariableIndex ) ); - + if (this.compile(cc.body)) { canCompleteNormally = true; if ( @@ -1386,10 +1385,15 @@ this.iClassLoader.OBJECT, // valueType pcLVIndex // localVariableIndex ); - if (this.compile(ts.optionalFinally)) { + boolean finallyCCN = this.compile(ts.optionalFinally); + if (finallyCCN) { this.writeOpcode(ts, Opcode.RET); this.writeByte(ts, pcLVIndex); } + // JLS 14.19.2, with no catch blocks + if (canCompleteNormally && !finallyCCN) { + canCompleteNormally = false; + } } afterStatement.set();