Find Bugs is Easy By- David H. Hovemeyer & William Pugh Summary by- Sahul Peermohammed.

Slides:



Advertisements
Similar presentations
Identity and Equality Based on material by Michael Ernst, University of Washington.
Advertisements

Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Exception Handling Xiaoliang Wang, Darren Freeman, George Blank.
Lab#1 (14/3/1431h) Introduction To java programming cs425
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
Fall 2007CS 225 Program Correctness and Efficiency Chapter 2.
14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
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.
Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide.
1 Testing Concurrent Programs Why Test?  Eliminate bugs?  Software Engineering vs Computer Science perspectives What properties are we testing for? 
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 18 Exception Handling.
Object Oriented Programming
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Ruthwika Bowenpalle,  Finding bugs :motivations.  Techniques for finding bugs.  general problem of finding bugs in software, and the strengths.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Evaluating and Tuning a Static Analysis to Find Null Pointer Bugs Dave Hovemeyer Bill Pugh Jaime Spacco.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
In the name of Allah The Proxy Pattern Elham moazzen.
Best Practices. Contents Bad Practices Good Practices.
Comp 249 Programming Methodology Chapter 13 Interfaces & Inner Classes Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Object Oriented Software Development
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Inheritance (Part 5) Odds and ends 1. Static Methods and Inheritance  there is a significant difference between calling a static method and calling a.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance (Part 2) KomondorBloodHound PureBreedMix Dog Object.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
M1G Introduction to Programming 2 5. Completing the program.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
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?
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Agenda Introduction Errors and Exception Exception Hierarchy Classification of Exceptions Built in Exceptions Exception Handling in Java User defined.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
SE-1021 Software Engineering II
Inheritance and Polymorphism
Java Programming Language
Introduction Enosis Learning.
Introduction Enosis Learning.
Java Programming Language
Exception Handling.
Presentation transcript:

Find Bugs is Easy By- David H. Hovemeyer & William Pugh Summary by- Sahul Peermohammed

Introduction Bugs are a serious problem Tools offer tremendous promise for improving software quality. Lots of research done in this field. Some of the techniques proposed in this research require sophisticated program analysis. Find Bugs is a simple static analysis technique based on the notion of Bug patterns. A Bug pattern is a code idiom that is likely to be an error

Motivation “US companies alone are spending almost £40 billion pound annually on defective software- one third of software market”. [SourceNinja] 1 “Smart ship USS Yorktown- US Navy ship was left dead in the water in 1997 for nearly 3 hours after a divide by zero error” [Wikipedia] 2 Raise awareness of the large number of easily-detectable bugs that are not caught by traditional quality assurance techniques Suggest possibilities for future research  Ways to integrate automatic bug finding techniques into the development process

Techniques for finding bugs Manual Code inspections  Requires intensive manual effort  Influenced by what a piece of code is intended to do Automatic Code inspections 1.Dynamic techniques Advantage is that they do not consider infeasible paths in a program. Disadvantage being it is significant complex to achieve high statement or branch coverage. 2.Static techniques Formal proof of correctness. Some techniques may be complete or incomplete. Unsound techniques can identify “probable” bugs, but may miss some real bugs and also may emit some inaccurate warnings.

Bug checkers vs. Style checkers Bug Checker  Bug checker checks for violation of a specific correctness property, and which may cause misbehavior at runtime.  Affects users of the software.  Requires judgment in order to understand the cause of the bug, and to fix it without introducing new bugs. Style Checker  Style checker determines if code violates a particular coding style rule.  Affects the developers working on the software.  Fixed easily by changing code to adhere to style guidelines and improving the understandability of the code

FindBugs Tool Open source. Originally contained 50 bug detectors. Now has more than 200 bug detectors. Pattern implemented using BCEL(Byte Code Engineering Library), an open source bytecode analysis and instrumentation library. Implementation strategies used by the detectors can be divided into several rough categories:  Class structure and inheritance hierarchy only  Linear code scan  Control sensitive  Dataflow

Bug Patterns and detectors Authors have described a few bug patterns Each detector falls under following categories:  Single-threaded correctness issue  Thread/synchronization correctness issue  Performance issue  Security and vulnerability to malicious untrusted code

Open Stream (OS) Good practice to close stream when it becomes unreachable. Although Finalizers ensure I/O streams are automatically closed when garbage collected. But no guarantee that this will happen in a timely manner. Why to close the stream after use? Operating system has limited resource, and running out of them may cause the program to misbehave. The data stored in the stream’s buffer may never be written to the file.

Uses dataflow analysis to determine all of the instructions reached by the definitions. Checks if a stream in the open state reaches the exit block of the control flow graph for a method. private static File _parsePackagesFile( File packages, File destDir) { try { FileReader fr = new FileReader(packages); BufferedReader br = new BufferedReader(fr);... // fr/br are never closed Open Stream (OS)

Uninitialized Read In Constructor (UR) Each field set to its default value for its type when constructed. Not useful to read a field before a value is written to it. This detector checks in Constructor whether any field is read before it is written. public SnapshotRecordingMonitor() { log = Logger.getLogger(monitorName); history = new ArrayList(100); }

Non-Short-Circuit Boolean Operator (NS) Java’s && and || operators follows short-circuit evaluation. Often used to test a reference value against null, and call a method if the reference is found not to be null. Non-short-circuiting & and | operators are also defined for boolean values. Programmer’s unintentionally use one of these operators where they intended to use a short-circuiting boolean operator. Because both boolean expressions are evaluated unconditionally, a null pointer exception may result. if(cheatSheet != null & cheatSheet.getTitle() != null) return cheatSheet.getTitle();

Non-serializable Serializable class (SE) Looks for classes that implement Serializable interface but cannot be serialized. Transient field: Objects will not be included when the object is serialized. Detector checks for two main factors:  It contains a non-transient instance field of a type that does not implement Serializable, or  The superclass of the class is not serializable.

Static Field Modifiable By Untrusted Code (MS) Untrusted code allowed to modify static fields, thereby modifying the behavior of the library for all users. Detector looks for following factors:  A static non-final field has public or protected access.  A static final field has public or protected access and references a mutable structure such as an Array or Hashtable.  A method returns a reference to a static mutable structure such as an array or Hashtable.

Null Pointer Dereference (NP), Redundant Comparison to Null (RCN) Detector uses data flow control to check for these types of issues. Null pointer dereference: Control c= getControl(); if (c == null && c.isDisposed()) return; Redundant null comparison if (m.parent != this) { add(m); } helpMenu = m; if (m != null) { …….

Cloneable Not Implemented Correctly (CN) Checks whether a class implements Cloneable interface correctly. Violation is to not call super.clone(), but rather allocate a new object by invoking a constructor. super.clone() ensure that they all delegate object creation to Object.clone(), which automatically creates a new object of the correct class. For e.g. Suppose class ("A") does not call super.clone(), and class ("A") is extended by a subclass ("B"), and the subclass B calls super.clone(), then it is likely that B's clone() method will return an object of type A, which violates the standard contract for clone().

Suspicious Equals Comparison (EC) Uses intra-procedural dataflow analysis to determine objects of types known to be incomparable are compared. According to the contract of equals(), objects of different classes should always compare as unequal. Result of this comparison will always be false at runtime.

Dropped Exception Looks for a try-catch block where the catch block is empty and the exception is slightly discarded. Programmers believe the exception cannot occur. Ignoring the exception can create incorrect anomalous behavior that could be very hard to track down. Exceptions should be handled or reported in some way, or they should be thrown out of the method.

Return Value Should Be Checked (RV) Java libraries have a number of immutable classes.  For e.g. once constructed, Java String objects do not change value. Methods that transform a String value do so by returning a new object  Any String method returning a String  StringBuffer.toString()  Any method of InetAddress, BigInteger, or BigDecimal  MessageDigest.digest(byte[])

Read Return Should Be Checked (RR) java.io.InputStream class has two read() methods which read multiple bytes into a buffer. These methods return an integer indicating how many bytes were read. Programmers sometimes assume these methods always return the requested number of bytes. However, some input streams (e.g. sockets) can return short reads. If return value from these methods is ignored, the program may read uninitialized/stale elements in the buffer. The detector uses dataflow analysis & determines whether or not the location where the return value of a call to read() is stored is ever used by another instruction

int length = input.readInt(); byte[] byteArray = new byte[length]; input.read(byteArray, 0, length); if (length >= 4){... Read Return Should Be Checked (RR)

Unconditional Wait (UW) Threads using wait() and notify() is a frequent source of errors in multithreaded programs. Looks for code where a wait is performed unconditionally in a synchronized block. Indicates that the condition associated with the wait was checked without a lock held and notification performed by another thread could have been missed. Detector for this bug pattern uses a linear scan over method’s bytecode. // If we are not enabled, then wait if (!enabled) { try { synchronized (lock) { lock.wait();...

Wait Not In Loop (Wa) Similar to the previous problem. synchronized (object) { if ( ) { object.wait(); } // Proceed when condition holds } Should be: synchronized (object) { while ( ) { object.wait(); } // Proceed when condition holds }

Equal Objects Must Have Equal Hashcodes (HE) For Java objects to be stored in HashMaps and HashSets, they must implement both the equals(Object) and hashCode() methods if either of them is overridden. Objects which compare as equal must have the same hashcode. Consider a case where a class overrides equals() but not hashCode(). The default implementation of hashCode() in the Object class returns an arbitrary value assigned by the virtual machine. It might result in objects of this class to be equal without having the same hashcode. Detector checks for the easy cases such as:  Classes which redefine equals(Object) but inherit the default implementation of hashCode()  Classes which redefine hashCode() but do not redefine equals(Object) Detector uses simple analysis of method signatures and the class hierarchy.

Bad Covariant Definition of Equals (Eq) Classes may override the equals(Object) method. Programmers sometimes mistakenly use the type of their class Foo as the type of the parameter to equals(): public boolean equals(Foo obj) {...} Does not override the version in the Object class, which may lead to unexpected behavior at runtime. If the class is used with one of the standard collection classes which expect that the standard equals(Object) method is overridden. Detector simply examines the method signatures of a class and its superclasses.

Classification of Bug Patterns Fix is a judgment call Some bug pattern detectors are very accurate, but determining whether to fix is up to the programmer. False positives. Some the bug detectors admit false positives, and report warnings in cases where the situation described by the warning does not, in fact occur Mostly harmless bugs The warning may reflect a violation of good programming practice but be unlikely to cause problems in practice. Serious bugs warning is accurate and in our judgment reflects a serious bug that warrants fixing

Evaluation Authors ran FIndBugs(v 0.8.4) on a few applications and classified the bugs reported under several categories as shown in the following table : GNU Classpath, version 0.08 an open source implementation of the core Java runtime libraries rt.jar from Sun JDK 1.5.0, build 59 Sun’s implementation of the APIs for J2SE Eclipse, version 3.0 IDE DrJava, version stable IDE JBoss, version 4.0.0RC1 Java application server jEdit, version 4.2pre15 programmer’s text editor

Why Bugs Occur Everyone makes dumb mistakes Programmer intended to use the && operator, but mistakenly used the || operator. Java offers many opportunities for latent bugs Number of patterns and requirements that are not checked by the compiler but simply result in runtime errors when violated. Programming with threads is harder than people think. Programmers are not as scared of using threads as they should be Concurrency bugs are especially problematic because they can be extremely difficult to reproduce.

Questions & Feedback? Thank You! 32

References 1 => cheap-so-why-arent-more-companies-doing-more-stop-them/ cheap-so-why-arent-more-companies-doing-more-stop-them/ 2 => print/17_17/ html?topic=news print/17_17/ html?topic=news Finding bug is easy: &CFTOKEN= &CFTOKEN= Bad Covariant Definition of Equals (Eq): nding-bugs-matter-findbugs nding-bugs-matter-findbugs