1 Exposing Behavioral Differences in Cross-Language API Mapping Relations Hao Zhong Suresh Thummalapenta Tao Xie Institute of Software, CAS, China IBM.

Slides:



Advertisements
Similar presentations
Automating Software Module Testing for FAA Certification Usha Santhanam The Boeing Company.
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Topics Introduction Types of Errors Exceptions Exception Handling
CSCI 160 Midterm Review Rasanjalee DM.
Exception Handling. Background In a perfect world, users would never enter data in the wrong form, files they choose to open would always exist, and code.
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Objectives In this chapter you will: Learn what an exception is Learn how to handle exceptions within a program See how a try / catch block is used to.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
Exception Handling 1 CISC6795, Spring Introduction 2 Exception – an indication of a problem that occurs during a program’s execution, for examples:
© The McGraw-Hill Companies, 2006 Chapter 15. © The McGraw-Hill Companies, 2006 Exceptions an exception is an event that occurs during the life of a program.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Chapter 10.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
AspectJ2EE/Clasa Israel Institute of Technology The Computer Science department Itay Maman.
Guide To UNIX Using Linux Third Edition
1.2 Language Processing Activities The fundamental language processing activities divided into two parts. 1. Program generation activities 2. Program execution.
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
University of Toronto Department of Computer Science © 2001, Steve Easterbrook CSC444 Lec22 1 Lecture 22: Software Measurement Basics of software measurement.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Mining and Analysis of Control Structure Variant Clones Guo Qiao.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Java Programming: Guided Learning with Early Objects
SE: CHAPTER 7 Writing The Program
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
Computer Science Automated Software Engineering Research ( Mining Exception-Handling Rules as Conditional Association.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
Alattin: Mining Alternative Patterns for Detecting Neglected Conditions Suresh Thummalapenta and Tao Xie Department of Computer Science North Carolina.
Short Read Mapper Evan Zhen CS 124. Introduction Find a short sequence in a very long DNA sequence Motivation – It is easy to sequence everyone’s genome,
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New Mexico USA March 17, 2005 Hui Wu, Jeff Gray, Marjan Mernik,
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Chapter 9: Completing the Basics. In this chapter, you will learn about: – Exception handling – Exceptions and file checking – The string class – Character.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Random Test Generation of Unit Tests: Randoop Experience
Static model noOverlaps :: ArgumentCandidate[] candidates -> discrete[] types for (i : (0.. candidates.size() - 1)) for (j : (i candidates.size()
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
A Framework for Automated and Composable Testing of Component-based Services Miguel A. Jiménez, Ángela Villota, Norha M. Villegas, Gabriel Tamura, Laurence.
CAR-Miner: Mining Exception-Handling Rules as Sequence Association Rules Suresh Thummalapenta and Tao Xie Department of Computer Science North Carolina.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Secure Coding Rules for C++ Copyright © 2016 Curt Hill
SE-1021 Software Engineering II
User-Written Functions
Operating System Interface between a user and the computer hardware
Chapter 14: Exception Handling
College of Computer Science and Engineering
Exception Handling Oo28.
Presentation transcript:

1 Exposing Behavioral Differences in Cross-Language API Mapping Relations Hao Zhong Suresh Thummalapenta Tao Xie Institute of Software, CAS, China IBM Research, India NC State University, USA

2  Many programming languages are introduced over decades Motivation  Business requirements force companies to release applications in multiple languages  E.g., Lucene and WordNet have both Java and C# variants Three major reasons for developing variants in multiple languages  For API libraries, to attract a large number of programmers  For stand-alone applications, to acquire specific features of underlying languages  For mobile applications, to support multiple platforms

3  Develop in one language and translate to other languages  Example applications: Lucene.Net and Db4o  Advantage: significant reduction of effort  Many translation tools already exist  E.g., Java2CSharp, Net2Java  Key idea: replace APIs of one language with their corresponding APIs in another language via API mapping relations Trends in Developing Variants

4  Associate APIs of one language with APIs of the other language What Are API Mapping Relations?  Help translate code from one language to the other language

5  Mapped APIs can have behavioral differences  Differences among outputs or exceptions being thrown  Such differences lead to defects in translated code Problem An Example from Lucene project  Substring API  Java: 2 nd parameter represents end index  C#: 2 nd parameter represents #characters

6  Are such behavioral differences pervasive?  What types of behavioral differences are there?  What types of differences are more common than others?  Are these differences easy to be resolved? Goals of Our Study

7  Mapping relations are not available explicitly and take long time to be written manually  Extraction from tools : translation tools use different formats for specifying API mapping relations  Extraction from translated code: applications under translation may not cover APIs of interest  Extraction from translated code: translated code typically has compilation errors, not feasible for testing Challenges

8  A tool chain, called TeMAPI, that detects behavioral differences among API mapping relations  Empirical results showing  Behavioral differences are pervasive  8 findings on exposed behavioral differences and implications to API-library implementers&users  Behavioral differences indicating defects in translation tools, and 4 defects were confirmed by developers Major Contributions

9  Motivation  Study Setup  Empirical Results  Conclusion Outline

10  Subject libraries Study Setup  Includes two major steps

11  Create wrapper for each API method in one lang  Apply translation tools on the wrapper  Extract the mapping relation from original & translated wrappers  Ignore a mapping relation if the translated wrapper does not compile Step 1: Extract Mapping Relations

12 Step 2: Generate Test Cases Original Wrapper Translated Wrapper Apply translation tool Original Test case Translated Test case Generate test on original wrapper Execute test on translated wrapper Apply translation tool  Two existing state-of-the-art test generation tools  Pex: a dynamic-symbolic-execution-based test generation tool  Randoop: a feedback-guided random test generation tool

13  Motivation  Study Setup  Empirical Results  Conclusion Outline

14  We address the following research questions:  Are behavioral differences pervasive in cross- language API mapping relations?  What are the characteristics of behavioral differences concerning inputs and outputs?  What are the characteristics of behavioral differences concerning method sequences? Research Questions

15 Columns E-Tests: #exception-causing test cases Column A-Tests: #assertion-failing test cases RQ1: Pervasiveness About 50% of the generated test cases fail: Behavioral differences are pervasive in API mapping relations between Java and C#

16  Finding % - handling of null inputs.  Java.lang.Integer.parseInt(null, 10) ->NumberFormatException  System.Convert.ToInt32(null, 10)->0  Implication  API-library implementers should clearly define behaviors of null inputs  Programmers should handle null inputs carefully. RQ2: Findings and Implications

17  Finding % - returned string values.  ToString vs toString  GetName vs getName  Implication  A method in Java and a method in C# typically return different string values even if they have the same functionality. ▪ Programmers should be cautious while using these values. RQ2: Findings and Implications

18  Finding % - input domains.  java.lang.Boolean.parserBoolean(“test”)->false  System.Boolean.Parse(“test”)->FormatException.  Implication  Programmers should be cautious while dealing with methods with odd input values. RQ2: Findings and Implications

19  Finding % - implementations.  java.lang.Character.isJavaIdentifierPart(“\0”)->true  ILOG.J2CsMapping.Util.Character.IsCSharpIdentifie rPart (“\0”)->false  Implication  Some differences reflect different natures of different languages, and some others indicate defects in translation tools. ▪ Programmers should learn the natures of different programming languages to figure out such differences, e.g., different definitions of paths and files. RQ2: Findings and Implications

20  Finding % - handling of exceptions.  Implication  API-library implementers may design different exception-handling mechanisms.  If programmers do not notice these differences, they may introduce dead or defective code java.lang.StringBuffer.insert(int,char)->ArrayIndexOutofBoundsException System.Text.StringBuilder.Insert(int, char)-> ArgumentOutOfRangeException IndexOutOfRangeException RQ2: Findings and Implications

21  Finding % - constants.  java.lang.Double.MAX VALUE -> E+308  System.Double.MaxValue -> E+308  Implication  API-library implementers may store different values in constants, even if two constants have the same name.  Programmers should be careful to use constants. RQ2: Findings and Implications

22  Finding 7. Different inheritance hierarchies that can lead to compilation errors.  Implication  When programmers translate code (e.g., cast statements), they should be aware of such differences. StringBufferInputStream var4 =...; InputStreamReader var10 = new InputStreamReader((InputStream)var4, var8); StringReader var4 =...; StreamReader var10 = new StreamReader((Stream)var4, var8); StringBufferInputStream is a subclass of InputStream StringReader is NOT a subclass of Stream RQ3: Findings and Implications

23  Finding % - method sequences.  Implication  Legal method sequences can become illegal after translation, due to various factors such as constraints in the target programming language and field accessibility. DateFormatSymbols var0 = new DateFormatSymbols(); String[] var16 = new String[]...; var0.setShortMonths(var16); DateTimeFormatInfo var0 = System.Globalization.DateTimeFormatInfo.CurrentInfo; String[] var16 = new String[]...; var0.AbbreviatedMonthNames = var16; InvalidOperationException RQ3: Findings and Implications

24  Tool chain + empirical study of exposing behavioral differences of API mapping relations  Behavioral differences are pervasive and dangerous  8 findings with valuable implications for API-library implementers and users + 4 defects confirmed Conclusion Original WrapperTranslated Wrapper Apply translation tool Original Test caseTranslated Test case Generate test on original wrapper Execute test on translated wrapper Apply translation tool

25 Acknowledgment: NSF of China No , NSF of China No , NSF grants CCF , CCF , CNF , CNS , and an NSA Science of Security Lablet Grant

26  Tool chain + empirical study of exposing behavioral differences of API mapping relations  Behavioral differences are pervasive and dangerous  8 findings with valuable implications for API-library implementers and users + 4 defects confirmed Conclusion Original WrapperTranslated Wrapper Apply translation tool Original Test caseTranslated Test case Generate test on original wrapper Execute test on translated wrapper Apply translation tool