![]() |
|
![]() |
||||||||||
|
|
||||||||||||
NullSafe Patent-Pending TechnologySmart Bear has developed a unique, patent-pending algorithm to perform the complex task of real-world NullPointerExecption detection. Why finding NullPointerExceptions is hardConsider the following Java code snippet:
char getFirstChar( String s )
{
if ( s.length() == 0 )
return ' ';
return s.charAt( 0 );
}
The intent is to return the first character of a string, or a space character
if the string is empty. Of course if In this example, static analysis should be able to identify this possible bug without difficulty. So the user fixes the bug in the obvious way:
char getFirstChar( String s )
{
if ( s == null )
return ' ';
if ( s.length() == 0 )
return ' ';
return s.charAt( 0 );
}
A simple code-path analysis should now be able to detect that the
However this is not always the way such a bug is fixed. In fact, in this
example many Java developers would reailze that the Apache Jakarta Commons library
has a routine that better fits the purpose at hand.
(Lest the reader believes this is a contrived example, in a scan of the
Apache Tomcat project
(possibly the most-used servlet container in the world) we found
thousands of references to
import org.apache.commons.StringUtils;
char getFirstChar( String s )
{
if ( StringUtils.isEmpty( s ) )
return ' ';
return s.charAt( 0 );
}
Now the job of the static analysis engine gets harder. In order for the
code-path analysis to determine that
This adds complexity in several ways. First, function calls have to be
evaluted recursively. From a code-path point of view, the analysis has to
"go into"
Second, the result of the
Third, the code-path analysis must handle multiple data types. It has to know
that if an object-type input value is It gets worse. Consider this:
import org.apache.commons.StringUtils;
char getFirstChar( String s )
{
int n;
if ( StringUtils.isEmpty( s ) )
n = 0;
else
n = s.length();
bar(); /* always execute bar() */
if ( n >= 1 )
return s.charAt( 0 );
return ' ';
}
Several new concepts are at play. First, we're transferring information
about the possible
The analysis also has to know that if
Finally, the analysis needs to undestand that the check for The difficulties continue. Functions have to be followed recursively resulting in exponential growth in the amount of input/output information that has to be understood. Every time there is a conditional or a loop inside a function the possible number of code paths increases exponentially. Prior WorkPrevious attempts at making Java code null-safe have, of course, failed. We say "of course" because none of us are currently using any tool that finds the types of errors described above. NullSafe is the first one. Why have previous attempts failed? Previous attempts at NPE-detection have fallen victim to the kinds of complexity problems described in the previous section. No matter how sophisticated the code-path analysis or theorem-proving engine, no other system has been successfully applied to real-world code bases. Various short-cuts have been suggested that could make the problem of NPE-detection tractable. Our claim is that each of these proposals require trade-offs unacceptable to most development groups.
The Smart Bear NullSafe PatentWe have devised a way to scan code deeply and accurately enough to solve all the types of problems described in the first section, an in-memory and on-disk caching mechanism that stores enough information to be valuable but not so much that the cache becomes too large, and do it all while keeping exponential explosion of code paths and analysis in check. We cannot (yet!) divulge all the details of our methods because of the current stage of the patent. Once the patent because published, we will link to it and describe the method here in plain English. |
||||||||||||
|
|
CODE COLLABORATOR | CUSTOMERS | ARTICLES & WHITE PAPERS | TRAINING & CONSULTING | COMPANY | DOWNLOAD |
|
||||||||||
SMART BEAR SOFTWARE - "All your code review are belong to us." |
||||||||||||