Exception-Handling Bugs in Java and a Language Extension to Avoid Them [chapter]

Westley Weimer
2006 Lecture Notes in Computer Science  
It is difficult to write programs that behave correctly in the presence of exceptions. We describe a dataflow analysis for finding a certain class of mistakes made while programs handle exceptions. These mistakes involve resource leaks and failures to restore program-specific invariants. Using this analysis we have found over 1,200 bugs in 4 million lines of Java. We give some evidence of the importance of the bugs we found and use them to highlight some limitations of destructors and
more » ... . We propose and evaluate a new language feature, the compensation stack, to make it easier to write solid code in the presence of exceptions. These compensation stacks track obligations and invariants at run-time. Two case studies demonstrate that they can yield more natural source code and more consistent behavior in long-running programs.
doi:10.1007/11818502_2 fatcat:5mwtveb7v5g7tmjafr4eoacu6u