Download presentation
Presentation is loading. Please wait.
Published byBasil Mills Modified over 8 years ago
1
Findbugs Tin Bui-Huy September, 2009
2
Content What is bug? What is bug? What is Findbugs? What is Findbugs? How to use Findbugs? How to use Findbugs? Other static analysis tools for Java Other static analysis tools for Java
3
What is bug? An error or defect in software or hardware that causes a program to malfunction An error or defect in software or hardware that causes a program to malfunction
4
Bug fixing cost
5
What is Findbugs? Result of a research project at the University of Maryland Result of a research project at the University of Maryland Static analysis tool for Java Static analysis tool for Java
6
What is Findbugs? Not concerned by formatting or coding standards Not concerned by formatting or coding standards Concentrates on detecting potential bugs and performance issues Concentrates on detecting potential bugs and performance issues Can detect many types of common, hard-to-find bugs Can detect many types of common, hard-to-find bugs
7
How it works? Use “bug patterns” to detect potential bugs Use “bug patterns” to detect potential bugs Examples Examples Address address = client.getAddress(); if ((address != null) || (address.getPostCode() != null)) {... } public class ShoppingCart { private List items; public addItem(Item item) { items.add(item); } NullPointerException Uninitialized field
8
What Findbugs can do? FindBugs comes with over 200 rules divided into different categories: FindBugs comes with over 200 rules divided into different categories: Correctness Correctness E.g. infinite recursive loop, reads a field that is never written Bad practice Bad practice E.g. code that drops exceptions or fails to close file Performance Performance Multithreaded correctness Multithreaded correctness Dodgy Dodgy E.g. unused local variables or unchecked casts E.g. unused local variables or unchecked casts
9
How to use Findbugs ? Standalone Swing application Standalone Swing application Eclipse plug-in Eclipse plug-in Integrated into the build process (Ant or Maven) Integrated into the build process (Ant or Maven)
10
Steps to Run Findbugs Standalone Download Findbugs from http://findbugs.sourceforge.net/downloads.htm l Download Findbugs from http://findbugs.sourceforge.net/downloads.htm l http://findbugs.sourceforge.net/downloads.htm l http://findbugs.sourceforge.net/downloads.htm l Unzip the file Unzip the file Execute findbugs.bat Execute findbugs.bat
11
Steps to Run Findbugs Standalone Finbugs’ GUI brought up Finbugs’ GUI brought up Select File | New project Select File | New project
12
Steps to Run Findbugs Standalone Select byte code files and their source code Select byte code files and their source code [Point to jar files or class files] [Point to java files]
13
Steps to Run Findbugs Standalone FindBugs’ results FindBugs’ results
14
Selectively Suppressing Rules with FindBug Filters Select Edit | Preferences then move to Filter Select Edit | Preferences then move to Filter Add some filters that meet your expectation Add some filters that meet your expectation
15
Other static analysis tools for Java Checkstyle Checkstyle (see Chapter 21) (see Java Power Tools Chapter 21)Chapter 21Chapter 21 PMD PMD (see Chapter 22) (see Java Power Tools Chapter 22)Chapter 22Chapter 22
16
References (John Ferguson Smart, 2008) Java Power Tools (John Ferguson Smart, O'Reilly 2008)
17
Thank you!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.