Software Engineering Lab (LabSoft) 1/29 On The Detection of Code Clone With Concern Analysis Paiva, Alexandre; Alves, Johnatan;

Slides:



Advertisements
Similar presentations
Duplicate code detection using Clone Digger Peter Bulychev Lomonosov Moscow State University CS department.
Advertisements

A Mutation / Injection-based Automatic Framework for Evaluating Code Clone Detection Tools Chanchal Roy University of Saskatchewan The 9th CREST Open Workshop.
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
CS 206 Introduction to Computer Science II 01 / 20 / 2009 Instructor: Michael Eckmann.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
CS590 Z Matching Program Versions Xiangyu Zhang. CS590Z Problem Statement  Suppose a program P’ is created by modifying P. Determine the difference between.
Reverse Engineering © SERG Code Cloning: Detection, Classification, and Refactoring.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Extracting Code.
CS 206 Introduction to Computer Science II 09 / 09 / 2009 Instructor: Michael Eckmann.
1 Fall 2008ACS-1903 for Loop Reading files String conversions Random class.
Refactoring Support Tool: Cancer Yoshiki Higo Osaka University.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Software Engineering Lab, Osaka University Code Clone Analysis and Its Application Katsuro Inoue Osaka University.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Reverse Engineering State Machines by Interactive Grammar Inference Neil Walkinshaw, Kirill Bogdanov, Mike Holcombe, Sarah Salahuddin.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Mining Coding Patterns to Detect Crosscutting Concerns.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
CIS Computer Programming Logic
Robert Tairas (INRIA & EMN) Ferosh Jacob (University of Alabama) Jeff Gray (University of Alabama) International Workshop on Software Clones (IWSC) – May.
Detecting software clones in binaries Zaharije Radivojević, Saša Stojanović, Miloš Cvetanović School of Electrical Engineering, Belgrade University 14th.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A clone detection approach for a collection of similar.
Mining and Analysis of Control Structure Variant Clones Guo Qiao.
Today: Our process Assignment 3 Q&A Concept of Control Reading: Framework for Hybrid Experiments Sampling If time, get a start on True Experiments: Single-Factor.
2002/12/11PROFES20021 On software maintenance process improvement based on code clone analysis Yoshiki Higo* , Yasushi Ueda* , Toshihiro Kamiya** , Shinji.
1 Documenting with Javadoc. 2 Motivation  Why document programs? To make it easy to understand, e.g., for reuse and maintenance  What to document? Interface:
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
CMCD: Count Matrix based Code Clone Detection Yang Yuan and Yao Guo Key Laboratory of High-Confidence Software Technologies (Ministry of Education) Peking.
Cross Language Clone Analysis Team 2 October 27, 2010.
1 Gemini: Maintenance Support Environment Based on Code Clone Analysis *Graduate School of Engineering Science, Osaka Univ. **PRESTO, Japan Science and.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
1 Wright State University, College of Engineering Dr. T. Doom, Computer Science & Engineering CS 241 Computer Programming II CS 241 – Computer Programming.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Inoue Laboratory Eunjong Choi 1 Investigating Clone.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University How to extract.
Feasibility Study Cross-language Clone Analysis Team 2.
Toward an Implementation of the “Form Template Method” Refactoring Nicolas Juillerat University of Fribourg Switzerland.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
1 CSC 221: Computer Programming I Fall 2004 Lists, data access, and searching  ArrayList class  ArrayList methods: add, get, size, remove  example:
Maeda, Sill Torres: CLEVER CLEVER: Cross-Layer Error Verification Evaluation and Reporting Rafael Kioji Vivas Maeda, Frank Sill Torres Federal University.
With Jeff Gray and Ira Baxter Robert Tairas Visualization of Clone Detection Results Eclipse Technology Exchange Workshop OOPSLA 2006 Portland, Oregon.
Duplicate code detection using anti-unification Peter Bulychev Moscow State University Marius Minea Institute eAustria, Timisoara.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Finding Code Clones.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Sakai code exercises Aaron Zeckoski.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Cross Language Clone Analysis Team 2 February 3, 2011.
Scalable Clone Detection and Elimination for Erlang Programs Huiqing Li, Simon Thompson University of Kent Canterbury, UK.
CS 367 Introduction to Data Structures Lecture 2 Audio for Lecture 1 is available Homework 1 due Friday, September 18.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Classification.
 Software Clones:( Definitions from Wikipedia) ◦ Duplicate code: a sequence of source code that occurs more than once, either within a program or across.
Software Metric Tools Joel Keyser, Jacob Napp, Carey Norslien, Stephen Owings, Tristan Paynter.
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
1 Gemini: Code Clone Analysis Tool †Graduate School of Engineering Science, Osaka Univ., Japan ‡ Graduate School of Information Science and Technology,
1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Detecting Assumptions on Deterministic Implementations of Non-deterministic Specifications August Shi, Alex Gyori, Owolabi Legunsen, Darko Marinov 4/12/2016.
Coding #1 if(!(index < 0 || index >= list.size( )-1))
CBCD: Cloned Buggy Code Detector
A Refactoring Technique for Large Groups of Software Clones
ArraySet Methods and ArrayIterator
George Mason University
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Matching Program Versions
Defensive Programming
Presentation transcript:

Software Engineering Lab (LabSoft) 1/29 On The Detection of Code Clone With Concern Analysis Paiva, Alexandre; Alves, Johnatan; Figueiredo, Eduardo Software Engineering Lab (LabSoft) – Federal University of Minas Gerais (UFMG) Belo Horizonte – MG – Brazil {ampaiva, johnatan,

Software Engineering Lab (LabSoft) 2/29 Code Clone  Definition Copy and Paste [2] Similarity (not necessarily identical) is clone [3]

Software Engineering Lab (LabSoft) 3/29 Research Importance  Software Engineering Software quality, complexity, architecture, refactoring, evolution, licensing, plagiarism, and so on.  Workshops

Software Engineering Lab (LabSoft) 4/29 IWSC2014

Software Engineering Lab (LabSoft) 5/29 IWSC2015

Software Engineering Lab (LabSoft) 6/29 Example of Code Clone Type 1

Software Engineering Lab (LabSoft) 7/29 Detection Tools  Text based  Token based  Tree based  Graph based (PDG)  Metrics based  Hybrid techinique

Software Engineering Lab (LabSoft) 8/29 Concern Metrics  Quantify properties of concerns Scattering Tangling CandidateDate Statistics Log Persistence Exception Handling

Software Engineering Lab (LabSoft) 9/29 Motivation  Code clones should be avoided  Concern scattering should be avoided  Concern scattering as key for locating code clones Concern scattering differs from PDG when ignores local variables and statements

Software Engineering Lab (LabSoft) 10/29 Sonar (PurchaseOrderEJB.java x SupplierOrderEJB.java)

Software Engineering Lab (LabSoft) 11/29 Type 4  Semantic is the same int foo1(List clones){ int total = 0; for (int i = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if (!clone.isAvailable()) continue; total++; } return total; } int foo2(List list) { int count = 1, clones = 0; while (count <= list.size()) { if (list.get(count-1).isAvailable()) { clones = clones+1; } count = count+1; } return clones; }

Software Engineering Lab (LabSoft) 12/29 Type 4  Semantic is the same int foo1(List clones){ int total = 0; for (int i = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if (!clone.isAvailable()) continue; total++; } return total; } int foo2(List list) { int count = 1, clones = 0; while (count <= list.size()) { if (list.get(count-1).isAvailable()) { clones = clones+1; } count = count+1; } return clones; }

Software Engineering Lab (LabSoft) 13/29 I I String name List calls String name List calls name: health.data.UnitRDB.getPartial calls: java.util.ArrayList.ArrayList lib.util.Iterator.Iterator java.util.List.add java.sql.ResultSet.next List of Methods II String call List methods (position) String call List methods (position) call: java.util.List.add methods: health.data.UnitRDB.getPartial 2 health.view.Address.mount 3 health.data.Employee.save 6 Hash of Calls PROPOSAL APPROACH Project Sources... java xmlpngjava Duplications GitHub BitBucket Other GitHub BitBucket Other ConcernsComparision.java

Software Engineering Lab (LabSoft) 14/29 Systems Analyzed System Calls TotalDistinct Restaurantr Telestrada Learn Engh Mobile Media Ecommerce Health Watcher Ecommerce PetStore Junit Facebook Android Restaurant Open Maven ArgoUML JBoss

Software Engineering Lab (LabSoft) 15/29 Sequence Concept  3 calls in sequence int foo1(List clones){ int total = 0; for (int i = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if (!clone.isAvailable()) continue; total++; } return total; } int foo2(List list) { int count = 1, clones = 0; while (count <= list.size()) { if (list.get(count-1).isAvailable()) { clones = clones+1; } count = count+1; } return clones; }

Software Engineering Lab (LabSoft) 16/29 Clones per Sequence System CallsSequences of Calls TotalDistinct Restaurantr Telestrada Learn Engh Mobile Media Ecommerce Health Watcher Ecommerce PetStore Junit Facebook Android Restaurant Open Maven ArgoUML JBoss

Software Engineering Lab (LabSoft) 17/29 public Page getCategories(int start, int count, Locale locale) throws CatalogDAOSysExce ption { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { connection = getDataSource().getConnection(); String[] parameterValues = new String[] { locale.toString() }; if (TRACE) { printSQLStatement(sqlStatements, XML_GET_CATEGORIES, parameterValues); } statement = buildSQLStatement(connection, sqlStatements, XML_GET_CATEGORIES, pa rameterValues); resultSet = statement.executeQuery(); if (start >= 0 && resultSet.absolute(start + 1)) { boolean hasNext = false; List categories = new ArrayList(); do { categories.add(new Category(resultSet.getString(1).trim(), resultSet.ge tString(2), resultSet.getString(3))); } while ((hasNext = resultSet.next()) && (--count > 0)); return new Page(categories, start, hasNext); } return Page.EMPTY_PAGE;... Clone Detected – Petstore - getCategories

Software Engineering Lab (LabSoft) 18/29 Clone Detected – Petstore – getItems public Page getItems(String productID, int start, int count, Locale locale) throws Cata logDAOSysException { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { connection = getDataSource().getConnection(); String[] parameterValues = new String[] { locale.toString(), productID }; if (TRACE) { printSQLStatement(sqlStatements, XML_GET_ITEMS, parameterValues); } statement = buildSQLStatement(connection, sqlStatements, XML_GET_ITEMS, paramet erValues); resultSet = statement.executeQuery(); if (start >= 0 && resultSet.absolute(start + 1)) { boolean hasNext = false; List items = new ArrayList(); do { int i = 1; items.add(new Item(...)); } while ((hasNext = resultSet.next()) && (--count > 0)); return new Page(items, start, hasNext); } return Page.EMPTY_PAGE;...

Software Engineering Lab (LabSoft) 19/29 Comparison with Other Detectors  CloneDR  iClones

Software Engineering Lab (LabSoft) 20/29 Exercise Goal  12 snippets  To decide: Is code clone?

Software Engineering Lab (LabSoft) 21/29 Exercise Example

Software Engineering Lab (LabSoft) 22/29 Expected answers  Code is similar, but is not cloned. The sequence below should NOT be moved to a common method void foo1() { System.out.println("fileName: "+fileName+", orderId="+invoiceXDE.getOrderId()+", lineItemIds="+invoiceCDE.getLineItemIds()); System.exit(0); } void foo2() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.exit(0); }

Software Engineering Lab (LabSoft) 23/29 Expected answers  Code is clone. The sequence below should be moved to a common method void foo1() { System.out.println("fileName: "+fileName+", orderId="+invoiceXDE.getOrderId()+", lineItemIds="+invoiceCDE.getLineItemIds()); System.exit(0); } void foo2() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.exit(0); }

Software Engineering Lab (LabSoft) 24/29 Final Tips  The code clone is not the entire method  Code clone is just a piece of code, maybe three or more lines

Software Engineering Lab (LabSoft) 25/29 Exercise Survey 

Software Engineering Lab (LabSoft) 26/29 Survey Results

Software Engineering Lab (LabSoft) 27/29 Threats of Validation  Cases were randomically analysed  This approach can be already covered by another detection method  Survey was not representative Few subjects Bad cases Background

Software Engineering Lab (LabSoft) 28/29 Conclusions  Potential tool for Type 4 clone detection  Found clones which were not found by other tools  Performance was not focus, but large system was analysed  Tool can be improved  Hybrid solution may be an option

Software Engineering Lab (LabSoft) 29/29 Thanks! This work was partially supported by CNPq (grant Universal /2013-5) and FAPEMIG (grants APQ and PPM )