Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would try Findbugs and PMD. If neither of those detect the bug, the next thing to try would be to see if you could create a custom PMD checker that would detect this.</p> <p>Actually, statically detecting cases where a reference field is used before before it is initialized is likely to be difficult. I have a feeling that your example is one of the few cases that might be tractable. Consider this variation for example:</p> <pre><code>public class SettingsActivity extends PreferenceActivity { private String mTest; @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); mTest.replace("a", "b"); } public void setTest(String test) { mTest = testl; } } </code></pre> <p>Determining whether the suspect line could result in an NPE requires an analysis of the code base to see is <code>setTest</code> is ever called. And even then, you've only determined that an NPE <em>may</em> not occur ... not that it <em>will</em> not occur.</p> <hr> <p>References:</p> <ul> <li><a href="https://stackoverflow.com/questions/6724627/is-there-any-tools-for-finding-null-pointer-exception-in-java-files">Is there any tools for finding Null pointer exception in java files..?</a></li> <li><a href="https://stackoverflow.com/questions/2794928/npe-annotation-scenarios-and-static-analysis-tools-for-java">NPE annotation scenarios and static-analysis tools for Java</a> - which talks about a different, but related problem.</li> <li><a href="http://www.codeproject.com/Articles/26224/Static-Analysis-on-Steroids-Parasoft-BugDetective" rel="nofollow noreferrer">http://www.codeproject.com/Articles/26224/Static-Analysis-on-Steroids-Parasoft-BugDetective</a> - BugDetective uses flow analysis which is more likely to find problems with uninitialized variables.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload