Static Code Analysis to Find Bugs Wright.edu CS7140 Spring 2013 (Slides collected from many sources)

Slides:



Advertisements
Similar presentations
Vincent Massol, 1 st December 2006 Quality with Maven2.
Advertisements

11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Darryl Parks.  About Code Analysis, not Run-Time monitoring  This Presentation is NOT about Performance Analysis Tools  Profiling  Jconsole or other.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
Exception Handling Chapter 12.  Errors- the various bugs, blunders, typos and other problems that stop a program from running successfully  Natural.
Coding Standards for Java An Introduction. Why Coding Standards are Important? Coding Standards lead to greater consistency within your code and the code.
Engineering Secure Software. The Power of Source Code  White box testing Testers have intimate knowledge of the specifications, design, Often done by.
CSE 341, Winter Type Systems Terms to learn about types: –Type –Type system –Statically typed language –Dynamically typed language –Type error –Strongly.
Cole Cecil. Peer Code Review 2 Why do a peer code review? Find defects earlier Find different kinds of defects Share knowledge among peers Maintainability.
© 2010 John Dalbey Ch 9: Reviews Humphrey proposes that personal reviews will result in improved quality. Now that we have a defined process and some real.
Coding concerns, are they real? Fadi Wedyan, Dalal Alrmuny May 10 th, 2007.
Applied Software Project Management Andrew Stellman & Jennifer Greene Applied Software Project Management Applied Software.
JArchitect Benefits by CoderGears
Examining the Code [Reading assignment: Chapter 6, pp ]
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
CSE 6329 Project Team 1 Aliasgar Kagalwala Aditya Mone Derek White Dengfeng (Thomas) Xia.
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Success status, page 1 Collaborative learning for security and repair in application communities MIT & Determina AC PI meeting July 10, 2007 Milestones.
Chapter 12: Exception Handling
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
Coverage tools Program is typically compiled with special options, to add extra source or object code. –Additional data structures, such as a flow graph,
(1) Automated Quality Assurance Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 22 Slide 1 Verification and Validation Slightly adapted by Anders Børjesson.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSCE 548 Code Review. CSCE Farkas2 Reading This lecture: – McGraw: Chapter 4 – Recommended: Best Practices for Peer Code Review,
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
INFSO-RI JRA2: Testing senarious ETICS AH meeting Budapest, Iune 2009 Eva Takacs, Jozsef Kuti, András Milassin 4D Soft.
Reviewing Recent ICSE Proceedings For:.  Defining and Continuous Checking of Structural Program Dependencies  Automatic Inference of Structural Changes.
Java Coding Standards and Best Practices Coding Standards Introduction: After completing this chapter, you will able to keep your code up to standards.
CS 350, slide set 5 M. Overstreet Old Dominion University Spring 2005.
From Quality Control to Quality Assurance…and Beyond Alan Page Microsoft.
16 October Reminder Types of Testing: Purpose  Functional testing  Usability testing  Conformance testing  Performance testing  Acceptance.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Winter 2005SE-280 Dr. Mark L. Hornick Personal Software Process: Initial Process Overview.
Refactoring1 Improving the structure of existing code.
1 Evaluating Code Duplication Detection Techniques Filip Van Rysselberghe and Serge Demeyer Lab On Re-Engineering University Of Antwerp Towards a Taxonomy.
Software Testing and Maintenance 1 Code Review  Introduction  How to Conduct Code Review  Practical Tips  Tool Support  Summary.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Refactoring & Testability. Testing in OOP programming No life in flexible methodologies and for refactoring- infected developers without SOME kind of.
(1) A beginners guide to testing Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Application of Design Heuristics in the Designing and Implementation of Object Oriented Informational Systems.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
MNP1163 (Software Construction).  SDLC and Construction Models  Construction Planning  Construction Measurement.
Findbugs Tin Bui-Huy September, Content What is bug? What is bug? What is Findbugs? What is Findbugs? How to use Findbugs? How to use Findbugs?
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Software Metric Tools Joel Keyser, Jacob Napp, Carey Norslien, Stephen Owings, Tristan Paynter.
INFSOM-RI A Quality Certification Model for Grid Research Projects the ETICS feasibility Study Adriano Rippa
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Refactoring1 Improving the structure of existing code.
Copyright 2015, Robert W. Hasker. Continuous Inspection  Code reviews  Powerful tool  Difficult to ensure meaningful reviews take place  Static analysis.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Automatic code inspection.
(1) Code Walkthrough robocode-pmj-dacruzer Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of.
Secure Programming with Static Analysis Brian Chess, Ph.D.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Copyright © 2010 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. ODS Tools – Fannie Mae.
Findbugs Tin Bui-Huy September, Content What is bug? What is bug? What is Findbugs? What is Findbugs? How to use Findbugs? How to use Findbugs?
Slide 1. What's New in NetBeans IDE 7.2 The following is intended to outline our general product direction. It is intended for information purposes only,
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
Chapter 8 – Software Testing
Improving the structure of existing code
Chapter 13 Quality Management
(Computer fundamental Lab)
White Box testing & Inspections
Computer Science 340 Software Design & Testing
Chapter 9: Implementation
Presentation transcript:

Static Code Analysis to Find Bugs Wright.edu CS7140 Spring 2013 (Slides collected from many sources)

Comparison of Defect-Detection Approaches

Inspections? The combination of design and code inspections usually removes percent or more of the defects in a product (Jones 1996). Designers and coders learn to improve their work through participating in inspections, and inspections increase productivity by about 20 percent (Fagan 1976, Humphrey 1989, Gilb and Graham 1993, Wiegers 2002). On a project that uses inspections for design and code, the inspections will take up about percent of project budget and will typically reduce overall project cost.

Best Results – Combine Approaches The typical organization uses a test-heavy defect-removal approach and achieves only about 85 percent defect­ removal efficiency. Leading organizations use a wider variety of techniques and achieve defect-removal efficiencies of 95 percent or higher (Gones 2000).

Code Review Tools Advantages of Code Review Tools – Track suggestions – Allow follow up on tasks – Aid in comparing before and after changes – Source Code repository integration Tools – Crucible – CodeCollaborator – Review Board – Rietveld – Code Striker

Code Analysis Tools FindBugs PMD CheckStyle Jdepend Ckjm Cpd Javancss Cobertura jlint

FindBugs A bug pattern is a code idiom that is often an error. – Difficult language features – Misunderstood API methods – Misunderstood invariants when code is maintaine – typos, wrong boolean operators, … static analysis to inspect Java bytecode for bug patterns. – Without executing the program – don't even need the program's source can report false warnings, and also miss real errors. – In practice, false warnings < 50%.

FindBugs Categories Bad practice Correctness Dodgy Experimental Internationalization Malicious code vulnerability Multithreaded correctness Performance Security

PMD scans Java source code and looks for potential problems like: Possible bugs - empty try/catch/finally/switch statements Dead code - unused local variables, parameters and private methods Suboptimal code - wasteful String/StringBuffer usage Overcomplicated expressions - unnecessary if statements, for loops that could be while loops Duplicate code - copied/pasted code means copied/pasted bugs

PMD RuleSets Android Rules: These rules deal with the Android SDK. Android Rules Basic Rules: The Basic Ruleset contains a collection of good practices which everyone should follow. Basic Rules Braces Rules: The Braces Ruleset contains a collection of braces rules. Braces Rules Clone Implementation Rules: The Clone Implementation ruleset contains a collection of rules that find questionable usages of the clone() method. Clone Implementation Rules Code Size Rules: The Code Size Ruleset contains a collection of rules that find code size related problems. Code Size Rules Controversial Rules: The Controversial Ruleset contains rules that, for whatever reason, are considered controversial. Controversial Rules Coupling Rules: These are rules which find instances of high or inappropriate coupling between objects and packages. Coupling Rules Design Rules: The Design Ruleset contains a collection of rules that find questionable designs. Design Rules Import Statement Rules: These rules deal with different problems that can occur with a class' import statements. Import Statement Rules JavaBean Rules: The JavaBeans Ruleset catches instances of bean rules not being followed. JavaBean Rules JUnit Rules: These rules deal with different problems that can occur with JUnit tests. JUnit Rules Java Logging Rules: The Java Logging ruleset contains a collection of rules that find questionable usages of the logger. Java Logging Rules Migration Rules: Contains rules about migrating from one JDK version to another. Migration Rules Migration15: Contains rules for migrating to JDK 1.5 Migration15 Naming Rules: The Naming Ruleset contains a collection of rules about names - too long, too short, and so forth. Naming Rules Optimization Rules: These rules deal with different optimizations that generally apply to performance best practices. Optimization Rules Strict Exception Rules: These rules provide some strict guidelines about throwing and catching exceptions. Strict Exception Rules String and StringBuffer Rules: Problems that can occur with manipulation of the class String or StringBuffer. String and StringBuffer Rules Security Code Guidelines: These rules check the security guidelines from Sun. Security Code Guidelines Unused Code Rules: The Unused Code Ruleset contains a collection of rules that find unused code. Unused Code Rules

PMD Rule Example PMD Basic Rules EmptyCatchBlock: Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported. EmptyIfStmt: Empty If Statement finds instances where a condition is checked but nothing is done about it. EmptyWhileStmt: Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. EmptyTryBlock: Avoid empty try blocks - what's the point? EmptyFinallyBlock: Avoid empty finally blocks - these can be deleted. EmptySwitchStatements: Avoid empty switch statements. JumbledIncrementer: Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. ForLoopShouldBeWhileLoop: Some for loops can be simplified to while loops - this makes them more concise.

CheckStyle Development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. Highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. Other sample configuration files are supplied for other well known conventions.Sun Code Conventions

CheckStyle Example

Dead Code Detector

Miscellaneous Tools CKJM - Chidamber and Kemerer Java Metrics Cobertura & EMMA – Test Code Coverage JavaNCSS - A Source Measurement Suite JDepend – Package Dependencies; Efferent Couplings (Ce) (number of other packages that the classes in the package depend upon) PMD-CPD - Copy/Paste Detector (CPD) Java2HTML - Source Code turned into a colorized and browseable HTML representation.

Structure Tools Struture For understanding, analyzing, measuring and controlling the quality of your Software Architecture as it evolves over time. Sotoarc/Sotograph — Architecture and quality in-depth analysis and monitoring for Java, Sotoarc/Sotograph _static_code_analysis _static_code_analysis

XRadar XRadar is an open extensible code report tool currently supporting all Java based systems. The batch-processing framework produces HTML/SVG reports of the systems current state and the development over time - all presented in sexy tables and graphs.

Sonar Dashboard to summarize Static and Dynamic analysis Tools. Conventions (Checkstyle) Bad Practices (PMD) Potential Bugs (FindBugs)

Sonar Application Dashboard

Sonar Violations Drilldown

Sonar Hotspots

IntelliJ Idea IDE FeaturesCommunity EditionUltimate Edition Code DuplicatesNoYes Code CoverageNoYes Code InspectorYes Spell CheckerYes More than 600 automated Code Inspections Finding probable bugs Locating the “dead” code Detecting performance issues Improving code structure and maintainability Conforming to coding guidelines and standards Conforming to specifications