March 31 – April 2, 2009
Data Flow Analysis:
Static Analysis on Steroids
Nada daVeiga,
Solution Architect, Parasoft
3 Types of Software Bugs
Poorly-implemented requirements
Missing or incomplete requirements
Confused user
How to Detect?
Poorly-implemented requirements
Regression testing
Confused user
Negative testing
Missing or incomplete requirements
Flow analysis
Static Analysis Background
Two main “schools”
1. Program execution/flow-based analysis
2. Pattern-based analysis
Benefits of Flow Analysis
Perform more comprehensive testing with existing
resources
Automatically identify defects that pass through
multiple classes
Focus on actual defects and misuses
Running Flow Analysis
TestField class - Involves a class instance field
that can be null
TestLocal class - Involves the same class with a
local variable that can be null
Both classes call a LocalHelper class. The goal is
to demonstrate how flow analysis handles
1. intra-procedural calls
2. inter-procedural calls (a) within one class
and (b) which cross class boundaries
Running Flow Analysis
Both of the examples contain instance field and
local variable variations of the same defects
The methods named “falsePositive” contain false
positives and the methods named “truePositive”
contain true positives
Results
Results – No False Positives
Flow analysis did not identify any false positives
Flow analysis found the defects in the
truePositives3 method to be false positives-- even
though other technologies report them as true
errors
Results – No False Positives
Object x; //NPE origin
TestFields(Object x) {
this.x = x;
}
int truePositive3(boolean b) {
Object y = null;
if (x != null)
y = new Object();
if (y != null)
return x.hashCode() +
y.hashCode();
else
return x.hashCode(); //NPE
}
Results – No False Positives
Instance variable x is initially initialized to null, but
it gets reassigned to the value of argument x in
the constructor call
Flow analysis saw a potential violation point on
the path but it did not see a path from the
violation origin statement to that line without
going through a constructor
This was not reported as a violation because the
flow analysis did not find a line where x is
initialized to null
Results – Flagging a True Positive
Add the following method to TestFields
void callerTruePositive3() {
TestFields tf = new TestFields(null);
tf.truePositive3(true);
}
Flow analysis now flags this violation since it sees
the violation origin and violation point, as well as
a code path that leads from one to the other
Pattern-Based Analysis vs. Flow-
Based Analysis
Prevention vs. detection
Accuracy
Types of defects
Ease of analysis
Final Thoughts
Flow analysis is one part of a comprehensive
quality and security strategy
Pattern-based static analysis
Metrics
Peer code review
Unit/component testing
Thank you!
For more information:
Nada daVeiga
Solution Architect
Parasoft
888-305-0041 x2433
[email protected]
http://www.parasoft.com