Computer Science Automated Software Engineering Research Group@NCSU () Mining Exception-Handling...

1
Computer Science Automated Software Engineering Research Group@NCSU (http://ase.csc.ncsu.edu) Mining Exception-Handling Rules as Conditional Association Rules Programmers often reuse APIs of existing frameworks or libraries to achieve high efficiency APIs throw exceptions during runtime errors Example: Session API of Hibernate framework throws HibernateException APIs expect client applications to implement recovery actions after exceptions occur Example: Session API expect client application to rollback uncommitted transactions after HibernateException occurs Failure to handle exceptions results in Fatal issues: Example: Database lock won't be released if the transaction is not rolled back Approach Suresh Thummalapenta [email protected] Challenges Lack of Specifications: Automatic static or runtime verification tools require the knowledge of specifications that must be obeyed while reusing the API methods. These specifications are often not available due to lack of documentation Approach Problem Open Source Repositories Code Search Engine Code Analyzer VIOLATIONS Input Application Application Scanner Class 1 Class 2 Code Downloader Local Source Code Repository Exception Flow Graphs Trace Generator Static Traces Trace Miner Conditional Association Rules Anomaly Detector Code Downloader: Leverage a code search engine to gather relevant code examples for all classes of the input application Code Analyser: Analyse code examples using heuristics as code examples are often partial and construct exception flow graphs Trace Generator: static traces from flow graphs Trace Miner: Generate conditional association rules by mining static traces Anomaly Detector: Detect violations of rules in the input application Evaluation Tao Xie [email protected] Example 1 . 1 : . . . 1 . 2 : O r a c l e D a t a S o u r c e o d s = n u l l ; S e s s i o n s e s s i o n = n u l l ; C o n n e c t i o n c o n n = n u l l ; S t a t e m e n t s t a t e m e n t = n u l l ; 1 . 3 : l o g g e r . d e b u g ( " S t a r t i n g u p d a t e " ) ; 1 . 4 : t r y { 1 . 5 : o d s = n e w O r a c l e D a t a S o u r c e ( ) ; 1 . 6 : o d s . s e t U R L ( " j d b c : o r a c l e : t h i n : s c o t t / t i g e r @ 1 9 2 . 1 6 8 . 1 . 2 : 1 5 2 1 : c a t f i s h " ) ; 1 . 7 : c o n n = o d s . g e t C o n n e c t i o n ( ) ; 1 . 8 : s t a t e m e n t = c o n n . c r e a t e S t a t e m e n t ( ) ; 1 . 9 : s t a t e m e n t . e x e c u t e U p d a t e ( " D E L E T E F R O M t a b l e 1 " ) ; 1 . 1 0 : c o n n e c t i o n . c o m m i t ( ) ; } 1 . 1 1 : c a t c h ( S Q L E x c e p t i o n s e ) { 1 . 1 3 : l o g g e r . e r r o r ( " E x c e p t i o n o c c u r r e d " ) ; } 1 . 1 4 : f i n a l l y { 1 . 1 5 : i f ( s t a t e m e n t ! = n u l l ) { s t a t e m e n t . c l o s e ( ) ; } 1 . 1 6 : i f ( c o n n ! = n u l l ) { c o n n . c l o s e ( ) ; } 1 . 1 7 : i f ( o d s ! = n u l l ) { o d s . c l o s e ( ) ; } } 1 . 1 8 : } S c e n a r i o 1 Defect : No rollback done when SQLException occurs Simple Specification: Connection Creation => Connection Rollback Formal specification: FCc1 FCc2 FCa => FCe1 FCc1 -> OracleDataSource.getConnection FCc2 -> Connection.createStatement FCa -> Statement.executeUpdate FCe1 -> Connection.rollback “ 4 -> 5 “ : Normal edge “ 5 -> 13 “ : Exception edge A trace for Node 7 4 -> 5 -> 6 -> 7 -> 15 -> 16 -> 17 Trace includes 3 parts Normal: 4 -> 5 -> 6 Function Call: 7 Exception: 15 -> 16 -> 17 Filtered trace 6 -> 7 -> 15 -> 16 Trace Miner Input: Two sequence databases SDB1 and SDB2 with 1- to-1 mapping Objective: Get association rules Annotate sequences to get a single combined database Apply frequent sequence mining algorithm [Wang and Han ICDE04] Transform mined sequences into association rules Real Rules Distribution of Rules for Axion Detected Violations HsqlDB developers responded on the first 10 reported defects Accepted 7 defects Accepted 3 defects Reason given by HsqlDB developers for rejected defects “Although it can throw exceptions in general, it should not throw with HsqlDB, So it is fineTo appear In Proceedings of 31 st International Conference on Software Engineering (ICSE), Vancouver, Canada, May 16 – 24, 2009 This work is supported in part by NSF grant CCF-0725190 and ARO grant W911NF-08-1-0443.

Transcript of Computer Science Automated Software Engineering Research Group@NCSU () Mining Exception-Handling...

Page 1: Computer Science Automated Software Engineering Research Group@NCSU () Mining Exception-Handling Rules as Conditional Association.

Computer Science

Automated Software Engineering Research Group@NCSU (http://ase.csc.ncsu.edu)

Mining Exception-Handling Rules as ConditionalAssociation Rules

Programmers often reuse APIs of existing frameworks or libraries to achieve high efficiency APIs throw exceptions during runtime errors

Example: Session API of Hibernate framework throws HibernateException APIs expect client applications to implement recovery actions after exceptions occur

Example: Session API expect client application to rollback uncommitted transactions after HibernateException occurs

Failure to handle exceptions results in Fatal issues: Example: Database lock won't be released if the transaction is not rolled back

Approach

Suresh Thummalapenta [email protected]

Challenges Lack of Specifications: Automatic static or runtime verification tools require the knowledge of specifications that

must be obeyed while reusing the API methods. These specifications are often not available due to lack of documentation

Approach

Problem

Open SourceRepositories

Code SearchEngine

CodeAnalyzer

VIOLATIONSInput

Application

ApplicationScanner

Class 1Class 2

CodeDownloader

Local SourceCode Repository

ExceptionFlow Graphs

Trace Generator

StaticTracesTrace Miner

ConditionalAssociation

Rules

AnomalyDetector

Code Downloader: Leverage a code search engine to gather relevant code examples for all classes of the input application

Code Analyser: Analyse code examples using heuristics as code examples are often partial and construct exception flow graphs

Trace Generator: static traces from flow graphs

Trace Miner: Generate conditional association rules by mining static traces

Anomaly Detector: Detect violations of rules in the input application

Evaluation

Tao [email protected]

Example1.1: .. .1.2: Orac leD ataS o urce o ds = nu ll; S ess ion sess ion = n ull; Co nn ec tio n conn = nu ll; S tatem e nt state m ent = n ull;1.3: logg er .deb ug ("S ta rt ing u pd ate");1.4: try {1.5: od s = n ew Ora c leD ataS ou rce( );1.6: od s.setUR L(" jdbc :orac le:thin:sco tt/t iger@ 1 92 .1 68 .1 .2 :152 1:catfish") ;1.7: conn = od s.g etCo nne c tio n() ;1.8: state m ent = co nn.cre ate S ta tem e nt( );1.9: state m ent .exe cuteU pda te("D E LE TE F RO M table 1") ;1.10 : conn ec tio n.com m it() ; }1.11 : catch (S QL Excep tio n se ) {1.13 : log ger .error ("E xcep tion o ccur re d"); }1.14 : f ina lly {1.15 : if(s ta te m en t != n ull) { s tatem e nt.clo se () ; }1.16 : if(conn != nu ll) { conn .c lose( ); }1.17 : if(od s != n ull) { o ds .clo se () ; } } 1.18 : }

S ce nar io 1

Defect : No rollback done when SQLException occurs

Simple Specification:

Connection Creation => Connection Rollback

Formal specification:FCc1 FCc2 FCa => FCe1

FCc1 -> OracleDataSource.getConnection

FCc2 -> Connection.createStatement

FCa -> Statement.executeUpdate

FCe1 -> Connection.rollback

“ 4 -> 5 “ : Normal edge “ 5 -> 13 “ : Exception edge A trace for Node 7

4 -> 5 -> 6 -> 7 -> 15 -> 16 -> 17 Trace includes 3 parts Normal: 4 -> 5 -> 6 Function Call: 7 Exception: 15 -> 16 -> 17

Filtered trace 6 -> 7 -> 15 -> 16

Trace Miner Input: Two sequence databases SDB1 and SDB2 with 1- to-1 mapping Objective: Get association rules Annotate sequences to get a single combined database Apply frequent sequence mining algorithm

[Wang and Han ICDE04] Transform mined sequences into association rules

Real Rules Distribution of Rules for Axion

Detected Violations

HsqlDB developers responded on the first 10 reported defects

Accepted 7 defects Accepted 3 defects

Reason given by HsqlDB developers for rejected defects

“Although it can throw exceptions in general, it should not throw with HsqlDB, So it is fine”

To appear In Proceedings of 31st International Conference on Software Engineering (ICSE), Vancouver, Canada, May 16 – 24, 2009 This work is supported in part by NSF grant CCF-0725190 and ARO grant W911NF-08-1-0443.