Shin Hwei Tan Darko Marinov Lin Tan Gary T. Leavens University of Illinois. University of Illinois

Similar documents
c 2012 Shin Hwei Tan

@tcomment: Testing Javadoc Comments to Detect Comment-Code Inconsistencies

@tcomment: Testing Javadoc Comments to Detect Comment-Code Inconsistencies

Automatic Generation of Oracles for Exceptional Behaviors

Feedback-directed Random Test Generation

Translating Code Comments to Procedure Specifications

Identifying Patch Correctness in Test-Based Program Repair

CalFuzzer: An Extensible Active Testing Framework for Concurrent Programs Pallavi Joshi 1, Mayur Naik 2, Chang-Seo Park 1, and Koushik Sen 1

Errors and Exceptions

How Good Are the Specs?

Exceptions. Errors and Exceptions. Dealing with exceptions. What to do about errors and exceptions

Object Oriented Programming. Week 7 Part 1 Exceptions

Which Configuration Option Should I Change?

Java Loose Ends. 11 December 2017 OSU CSE 1

Log System Based on Software Testing System Design And Implementation

Write for your audience

Alfresco repo under concurrent write load. Alexey Vasyukov, ITD Systems

Regression testing. Whenever you find a bug. Why is this a good idea?

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

Leveraging Test Generation and Specification Mining for Automated Bug Detection without False Positives

CUTE: A Concolic Unit Testing Engine for C

Program Correctness and Efficiency. Chapter 2

Fault, Error, and Failure

Static Analysis of C++ Projects with CodeSonar

Statically Checking API Protocol Conformance with Mined Multi-Object Specifications

FULLY AUTOMATIC AND PRECISE DETECTION OF THREAD SAFETY VIOLATIONS

16-Dec-10. Consider the following method:

Synchronization SPL/2010 SPL/20 1

Viola: A Verifier For Interoperating Components

Large-Scale API Protocol Mining for Automated Bug Detection

Natural language is a programming language

9/19/2018 Programming Data Structures. Polymorphism And Abstract

Comparing Non-adequate Test Suites using Coverage Criteria

acomment: Mining Annotations from Comments and Code to Detect Interrupt Related Concurrency Bugs

Automatic Test Generation. Galeotti/Gorla/Rau Saarland University

Automatically Generating Precise Oracles from Structured Natural Language Specifications

Exceptions, Case Study-Exception handling in C++.

Checked and Unchecked Exceptions in Java

Static program checking and verification

CSE wi Midterm Exam 2/8/18. Name UW ID #

Combined Static and Dynamic Automated Test Generation

Defensive Programming

Formal Methods for Java

Steps for project success. git status. Milestones. Deliverables. Homework 1 submitted Homework 2 will be posted October 26.

The Java Memory Model

Context-Based Detection of Clone-Related Bugs. Lingxiao Jiang, Zhendong Su, Edwin Chiu University of California at Davis

Object Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS 3 Introduction to Software Engineering. 3: Exceptions

public static void negate2(list<integer> t)

Object-Oriented Design. March 2005 Object Oriented Design 1

Automated Documentation Inference to Explain Failed Tests

Lecture 4 Specifications

public static boolean isoutside(int min, int max, int value)

Finding Concurrency Bugs in Java

CSE wi Midterm Exam 2/8/18 Sample Solution

JML tool-supported specification for Java Erik Poll Radboud University Nijmegen

CS 520 Theory and Practice of Software Engineering Fall 2018

Test automation / JUnit. Building automatically repeatable test suites

Test automation Test automation / JUnit

Implementing Rules. Java rules ok

In this lab we will practice creating, throwing and handling exceptions.

School of Informatics, University of Edinburgh

CS159. Nathan Sprague

SOftware defect prediction techniques [22], [29], [31], [41],

Automatic Generation of Program Specifications

JML. Java Modeling Language

Exception-Handling Overview

Main concepts to be covered. Handling errors. Some causes of error situations. Not always programmer error. Defensive programming.

CSE 331 Midterm Exam Sample Solution 2/18/15

ASSERTIONS AND LOGGING

COE318 Lecture Notes Week 10 (Nov 7, 2011)

ekey Error Codes Error Code Short Name Cause Message Resolution

CSE 331. Programming by contract: pre/post conditions; Javadoc

Chapter 16 Heuristic Search

Debugging and Testing Optimizers through Comparison Checking

Software Specifications. CMSC 433 Programming Language Technologies and Paradigms Spring Specifications Help You Write Code

CSE 331 Software Design & Implementation

Using Type Annotations to Improve Your Code

Classes, interfaces, & documentation. Review of basic building blocks

A Practical Approach to Programming With Assertions

A NOVEL APPROACH TO ERROR DETECTION AND CORRECTION OF C PROGRAMS USING MACHINE LEARNING AND DATA MINING

Symbolic Inference of Partial Specifications to Augment Regression Testing

Introduction to JML David Cok, Joe Kiniry, and Erik Poll Eastman Kodak Company, University College Dublin, and Radboud University Nijmegen

On Exceptions, Events and Observer Chains

Early detection of configuration errors to reduce failure damage

Automated SQL Ownage Techniques. OWASP October 30 th, The OWASP Foundation

Verification & Validation of Open Source

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions

An Industrial Evaluation of Unit Test Generation: Finding Real Faults in a Financial Application

Video 2.1. Arvind Bhusnurmath. Property of Penn Engineering, Arvind Bhusnurmath. SD1x-2 1

Projeto de Software / Programação 3 Tratamento de Exceções. Baldoino Fonseca/Márcio Ribeiro

CSE 331 Final Exam 6/5/17. Name UW ID#

NDSeq: Runtime Checking for Nondeterministic Sequential Specs of Parallel Correctness

Documentation (and midterm review)

CSE331 Winter 2014, Midterm Examination February 12, 2014

11 Using JUnit with jgrasp

Error Management in Compilers and Run-time Systems

Name: Class: Date: 2. Today, a bug refers to any sort of problem in the design and operation of a program.

Transcription:

Shin Hwei Tan Darko Marinov Lin Tan Gary T. Leavens University of Illinois University of Illinois University of Waterloo University of Central Florida 1

/* * Returns a synchronized map backed by the given map. * @param map the map to synchronize, must not be null * @return a synchronized map backed by the given map * @throws IllegalArgument if the map is null */ static <K,V> Map<K,V> synchronizedmap(map<k,v> map) Overall Description Block Tags @param - Parameter name, Description @return - Description @throws - name, Condition under which the exception is thrown 2

Writing Javadoc comments is a common practice Lots of Javadoc comments exist in Java libraries. Number of Number of Javadoc Ratio Project methods comments for methods (%) Collections 3,874 2,434 63 GlazedLists 2,753 1,741 63 JFreeChart 6,205 6,186 100 JodaTime 3,887 2,917 75 Log4j 2,115 958 45 Lucene 5,222 2,205 42 Xalan 5,404 3,229 60 3

/* * @param map the map to synchronize, must not be null * @return a synchronized map backed by the given map * @throws IllegalArgument if the map is null */ static <K,V> Map<K,V> synchronizedmap(map<k,v> map) Javadoc comments can be inconsistent with code Expected behavior for synchronizedmap (null): Throws IllegalArgument Actual behavior: Throws NullPointer 4

Important to find bugs in comments Comments are not executed Comments are read by developers to understand code Incorrect comments could cause developers to write wrong code [SOSP 07] Challenging to automatically analyze comments Ambiguities in understanding general text NLP made progress but struggles with general text 5

Build domain-specific analyses icomment (locking protocols & function calls) [SOSP 07] acomment (interrupts) [ICSE 11] System code (C/C++) Extract machine-checkable rules from comments Use static analysis to check consistency between code and comments/rules 6

Javadoc Comments Java Methods @tcomment Tests with Inconsistency New Domain Method properties for null values and related exceptions Dynamic Analysis (Random Testing) Fewer false alarms compared to static analysis Improved Testing Reduce false alarms in test generation tool Evaluation on 7 Libraries Found 28 inconsistencies, 12 were fixed 7

/* * @param map the map to synchronize, must not be null * @return a synchronized map backed by the given map * @throws IllegalArgument if the map is null */ static <K,V> Map<K,V> synchronizedmap(map<k,v> map) 8

/* * @param map the map to synchronize, must not be null * @return a synchronized map backed by the given map * @throws IllegalArgument if the map is null */ static <K,V> Map<K,V> synchronizedmap(map<k,v> map) 9

/* * @param map the map to synchronize, must not be null * @return a synchronized map backed by the given map * @throws IllegalArgument if the map is null */ static <K,V> Map<K,V> synchronizedmap(map<k,v> map) public void test1() throws Throwable { java.util.map var0 = null; try { java.util.map var1=...synchronizedmap(var0); } catch (IllegalArgument expected) {return;} fail("expected exception of type IllegalArgument but got NullPointer ); } 10

/* * @param map the map to synchronize, must not be null * @return a synchronized map backed by the given map * @throws IllegalArgument if the map is null */ static <K,V> Map<K,V> synchronizedmap(map<k,v> map) Confirmed & fixed by Collections developers public void test1() throws Throwable { java.util.map var0 = null; try { java.util.map var1=...synchronizedmap(var0); } catch (IllegalArgument expected) {return;} fail("expected exception of type IllegalArgument but got NullPointer ); } 11

/* * @param anchor the anchor (<code>null</code> not permitted). */ void setrotationanchor(textanchor anchor) 12

/* * @param anchor the anchor (<code>null</code> not permitted). */ void setrotationanchor(textanchor anchor) 13

/* * @param anchor the anchor (<code>null</code> not permitted). */ void setrotationanchor(textanchor anchor) public void test2() throws Throwable {...CategoryPointerAnnotation var0 = new CategoryPointerAnnotation( $0.00, (java.lang.comparable)'#', 10.0d, 10.0d); org.jfree.ui.textanchor var1 = null; try { var0.setrotationanchor(var1); fail("expected exception but got Normal Execution"); } catch ( expected) {} } 14

/* * @param anchor the anchor (<code>null</code> not permitted). */ void setrotationanchor(textanchor anchor) Confirmed & fixed by JFreeChart developers public void test2() throws Throwable {...CategoryPointerAnnotation var0 = new CategoryPointerAnnotation( $0.00, (java.lang.comparable)'#', 10.0d, 10.0d); org.jfree.ui.textanchor var1 = null; try { var0.setrotationanchor(var1); fail("expected exception but got Normal Execution"); } catch ( expected) {} } 15

@tcomment Javadoc Comments Infer properties Properties Java Methods Modified Randoop Tests with Inconsistency 16

@tcomment Javadoc Comments 2 Infer properties 1 Properties Java Methods Modified Randoop 3 4 Tests with Inconsistency 17

Null Normal, the method should execute normally (no exception) Eg: @param predicate the predicate to use, may be null Null Any, the method should throw some exception Eg: @param collection the collection to add to, must not be null Null Specific (id==null => IllegalArgumentExc), the method should throw a specific type of exception Eg: @throws IllegalArgument if the id is null Null Unknown, the method behavior is unknown Eg: @param array the array over which to iterate 1 18

Null Normal, the method should execute normally (no exception) Eg: @param predicate the predicate to use, may be null Null Any, the method should throw some exception Eg: @param collection the collection to add to, must not be null Null Specific (id==null => IllegalArgumentExc), the method should throw a specific type of exception Eg: @throws IllegalArgument if the id is null Null Unknown, the method behavior is unknown Eg: @param array the array over which to iterate 1 19

Null Normal, the method should execute normally (no exception) Eg: @param predicate the predicate to use, may be null Null Any, the method should throw some exception Eg: @param collection the collection to add to, must not be null Null Specific (id==null => IllegalArgumentExc), the method should throw a specific type of exception Eg: @throws IllegalArgument if the id is null Null Unknown, the method behavior is unknown Eg: @param array the array over which to iterate 1 20

Null Normal, the method should execute normally (no exception) Eg: @param predicate the predicate to use, may be null Null Any, the method should throw some exception Eg: @param collection the collection to add to, must not be null Null Specific (id==null => IllegalArgumentExc), the method should throw a specific type of exception Eg: @throws IllegalArgument if the id is null Null Unknown, the method behavior is unknown Eg: @param array the array over which to iterate 1 21

2 Parse Javadoc (Standard Doclet) Extract @param and @throws Analyze text 22

2 Parse Javadoc (Standard Doclet) Extract @param and @throws Analyze text Negation words (±3 distance within null) Null Any No negation words Null Normal null in @throws tag, then searches the list of parameter names. If found Null Specific param == null =>Specific Generates multiple properties for or and either in the @throws tag 23

while timelimit not reached: a. Create a new sequence 1. Randomly pick a method call m(t 1...T k ) 2. For each parameter, randomly pick a sequence S i that can construct the object for that parameter Select null with some probability (nullratio) 3. Create new sequence S new S 1;...S k ; m(var 1...var k ) b. Classify the new sequence S new Execute & check contract violations? - Output as failure-revealing test case No - Add to sequences if not redundant, else discard 24

3 while timelimit not reached: a. Create a new sequence 1. Randomly pick a method call m(t 1...T k ) 2. For each parameter, randomly pick a sequence S i that can construct the object for that parameter Select null with some probability (nullratio) 3. Create new sequence S new S 1;...S k ; m(var 1...var k ) b. Classify the new sequence S new Execute & check contract violations & @tcomment properties? Violate contract - Output as failure-revealing tests Violate properties - Output as comment-code inconsistency No - Add to sequences if not redundant, else discard 25

4 /** * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) 26

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) 27

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) 28

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) Execute 29

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) Execute Actual Thrown 30

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) Execute Actual Thrown Matches 31

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) Execute Actual Thrown Null Any Matches 32

4 /** Null Any * @param logger logger, may not be null. * @param sourceclass source class, may be null. * @param sourcemethod method, may be null. */ void exiting(logger logger, String sourceclass, String sourcemethod) Execute Actual Thrown Null Any Matches iscommentcodeinconsistency? 33

4 Throws? Execute 34

4 Throws? Execute No Null Any / Null Specific? 35

4 Execute Throws? No Null Any / Null Specific? Missing 36

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? 37

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? 38

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? Unexpected 39

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? Unexpected Unknown Status 40

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? Unexpected in the set of expected? Unknown Status 41

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? Unexpected in the set of expected? No Different Unknown Status 42

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? Unexpected in the set of expected? No Different Unknown Status Expected 43

4 Execute Throws? No Null Any / Null Specific? Missing 1 Null Specific? No 1 Null Normal? Unexpected in the set of expected? No Different Unknown Status Expected Missing Different Unexpected Unknown Status Expected Is Comment-code Inconsistency? 44

7 open source projects Ran @tcomment to infer properties Ran Modified Randoop to check properties Varying 2 options on Modified Randoop nullratio ( How often null is chosen as input for a method?) timelimit ( How long should Modified Randoop take for generating tests before stopping?) Best configuration for all projects nullratio = 0.6 timelimit = 3600s (reached plateau effect after that) 45

Project Description # LOC # Classes # Methods Collections Collection library and utilities 19,417 274 3,874 GlazedLists List transformations in Java 19,203 239 2,753 JFreeChart Chart creator 51,376 396 6,205 JodaTime Date and time library 18,428 154 3,887 Log4j Logging service 14,452 221 2,115 Lucene Text search engine 38,051 422 5,222 Xalan XML transformations 53,642 510 5,404 46

Project Missing Different Unexpected Unknown Status Expected Tested Properties Collections 12 4 6 94 36 115 GlazedLists 0 0 6 151 1 11 JFreeChart 1 0 2 127 6 42 JodaTime 3 0 13 37 3 31 Log4j 1 0 3 186 152 179 Lucene 4 0 2 368 2 12 Xalan 9 0 2 544 32 43 Total 30 4 34 1507 232 433 47

Project Missing Different Unexpected Unknown Status Expected Tested Properties Collections 12 4 6 94 36 115 GlazedLists 0 0 6 151 1 11 JFreeChart 1 0 2 127 6 42 JodaTime 3 0 13 37 3 31 Log4j 1 0 3 186 152 179 Lucene 4 0 2 368 2 12 Xalan 9 0 2 544 32 43 Total 30 4 34 1507 232 433 Tested only a fraction of properties inferred 48

Project Missing = TI + FA Different = TI + FA Unexpected = TI + FA Collections 12 + 0 3 + 1 0 + 6 GlazedLists 0 + 0 0 + 0 1 + 5 JFreeChart 1 + 0 0 + 0 2 + 0 JodaTime 3 + 0 0 + 0 0 + 13 Log4j 1 + 0 0 + 0 0 + 3 Lucene 0 + 4 0 + 0 1 + 1 Xalan 4 + 5 0 + 0 0 + 2 Total 21+ 9 3 + 1 4 + 30 True Inconsistencies (TI) Total 21 3 4 28 False Alarms (FA) 9 1 30 40 49

45% 27% 28% Incorrectly inferred properties Missing properties Incorrect/missing properties for another method Incorrect inference Wrong type of inferred properties Missing properties Missing property (Null Unknown) causes unexpected exception Incorrect/missing properties for another method Method under test depend on other method, other method causes unexpected exception 50

Project Precision [%] Recall [%] Accuracy Norm Any Spec Norm Any Spec [%] Collections 75 92 100 100 100 97 97 GlazedLists 100 100 100 100 100 100 100 JFreeChart 100 100 100 100 100 100 100 JodaTime 100 75 100 100 100 78 98 Log4j 100 100 100 100 100 100 100 Lucene 100 67 100 80 100 100 99 Xalan 50 100 100 100 100 100 99 Total/Overall 98 98 100 99 100 93 99 2 properties are inferred, 1 incorrect High accuracy (97-100%) 51

Comment-Code Inconsistency Detection Detected 28 comment-code inconsistencies 40 false alarms Comment Analysis Result High accuracy of 97 100% without using NLP techniques Javadoc comments are well-structured Not much variance in paraphrases 52

An inconsistency between comment and code is highly indicative of program faults @tcomment checks consistency of Java method bodies and Javadoc comments properties related to null values and exceptions Evaluated on 7 open-source projects Discovered 28 inconsistencies and 12 were already fixed Acknowledgement: Travel expenses sponsored by NSF CCF 07-46856 grants and ACM-W Scholarships for Attendance at Research Conferences. 53