# HG changeset patch # User Paul Boddie # Date 1106524014 -3600 # Node ID 9bbab006f98a050422bc29eb2f15a5b91b7158b7 # Parent a52e70c3f294e6505e9997327db157270caef830 Introduced exception table entry merging to try and preserve proper "finally" section handling. With the extra JDK 1.4 catch_type == 0 entries and the naive translation performed, multiple "finally" sections get created instead of a single section covering the entire original exception statement. This merging process attempts to identify redundant sections. diff -r a52e70c3f294 -r 9bbab006f98a javaclass/bytecode.py --- a/javaclass/bytecode.py Sun Jan 23 23:52:39 2005 +0100 +++ b/javaclass/bytecode.py Mon Jan 24 00:46:54 2005 +0100 @@ -746,9 +746,35 @@ # NOTE: Strange case with javac from JDK 1.4 but not JDK 1.3: # NOTE: start_pc == handler_pc - - if exception.start_pc == exception.handler_pc: - continue + # Merge all finally handlers with the same handler location. + + if exception.catch_type == 0 and exception_block_handler.get(exception.handler_pc, []) != []: + + # Make a new definition. + + new_exception = classfile.ExceptionInfo() + new_exception.catch_type = exception.catch_type + new_exception.handler_pc = exception.handler_pc + new_exception.end_pc = exception.end_pc + new_exception.start_pc = exception.start_pc + + # Find the previous exception handler definition. + + for previous_exception in exception_block_handler[exception.handler_pc][:]: + if previous_exception.catch_type == 0: + new_exception.end_pc = max(new_exception.end_pc, previous_exception.end_pc) + new_exception.start_pc = min(new_exception.start_pc, previous_exception.start_pc) + + # Remove this exception from the lists. + + exception_block_handler[previous_exception.handler_pc].remove(previous_exception) + exception_block_start[previous_exception.start_pc].remove(previous_exception) + exception_block_end[previous_exception.end_pc].remove(previous_exception) + break + + # Use the new definition instead. + + exception = new_exception # Index start positions.