1 Exception Analysis for Java Byeong-Mo Chang Sookmyung Women’s Univ., Korea
2 Contents Introduction Motivation Design of exception analysis Experiments and Related Works Conclusions
3 INTRODUCTION
4 Java overview Object oriented Type soundness –by Eisenbach97 and Nipkow98 Dynamic binding –inheritance and overriding Exception handling Concurrency
5 Constraint-based Analysis Constraint-based analysis [N. Heintze 1992] –static analysis framework for any languages –by defining set-constraint construction rules Constraint-based analysis –set-up constraints for programs by the rules –constraint solving algorithm Uncaught exception analysis –based on constraint-based analysis framework
6 MOTIVATION
7 Exceptions in Java Every exception is declared as –a subclass of “Exception” class Throw exceptions throw e Exception handling try { … } catch (E x) { … } Specify uncaught exceptions in method definition m(...) throws … { … }
8 Exceptions in Java Example class Demo { public static void main( ) { try { demoproc( ); } catch (Exception x) { ; } } void demoproc( ) throws Exception { try { throw new IOException("demo"); } catch (Exception x) { ; } }
9 Uncaught Exception Analysis in JDK Exception analysis –check whether thrown exceptions are caught or specified in the method definition –intra-procedural analysis based on programmer’s specifications. Not elaborate enough to –suggest for specialized handling nor –remove unnecessary handlers
10 Uncaught Exception Analysis We need an interprocedural analysis to –approximate all possible uncaught exceptions more precisely –independently of the programmer's specs. Exception analysis after class analysis –Assume Class(e) represents classes that are ``available'' at an expression e
11 Design of Exception Analysis
12 Deriving Set Constraints A set variable P e for every expression e –a set of names of uncaught exceptions from e. Construct set constraints of the form : P e se This analysis assigns class names of possible uncaught exceptions of e to P e
13 Deriving Set Constraints Suppose e is each of the following expressions id = e 1 | P e P e1 if e 0 then e 1 else e 2 | P e P e0 P e1 P e2 throw e 1 | P e Class(e 1 ) P e1 try e 0 catch (c x ) e 1 | P e (P e0 - {c}*) P e1 e 0.m(e 1 ) | - P e P e0 P e1 - for each class c in Class(e 0 ) with a method m(x 1 ) = e m c Class(e 0 ) P e P e m
14 Experiments & Related Works
15 Experiments on Exception Analysis 2-pass exception analyzer at method-level implemented using yacc pass1 set-ups constraints pass2 solves the constraints Testbed UltraSparc Enterprise 450 running Solaris
16 No.programsDescriptionNum of class Num of method Num of lines Kinds of Exns 1StatisticianList methods statistics for a class JavaBinHex BinHex(.hqx) decompressor JHLZIP Compress into ZIP file JHLUNZIP Decompress ZIP file Com.ice.tarUnix Tar Archive Jess-Rete Reasoning Engine of Java Expert System Shell Benchmark Programs (available at
17 No.Throws spec Catch block Uncaugt Exn Unnecessary throws Unnecessary catch Broader throws Broader catch (1) (0) (0) 03 (1)4 (2) (0)013 (2) Experimental Results ( ) : JDK results
18 Execution Time Jess-Rete Com.ice.tar 0.01 JHLUNZIP JHLZIP JavaBinHex Statistician Solving time (sec) Set-up time (sec) Programs
19 Related works Exception analysis for ML – constraint-based [Fahndrich&Aiken96 ], [Yi&Ryu97], – type and effect [Pessaux&Leroy99 ] Exception analysis for Java –designed with class analysis at method-level [Yi and Chang 99] Jex –A tool for a view of the exception flow [Robillard and Murphy 99]
20 Conclusions Exception analysis –a kind of program verification tool –can be incorporated in Java IDE Further works –Generalize sparse analysis by rule transformation –side-effect, security, synchronization