Harvesting the Wisdom of the Crowd to Infer Method Nullness in Java

Manuel Leuenberger, Haidar Osman, Mohammad Ghafari, and Oscar Nierstrasz. Harvesting the Wisdom of the Crowd to Infer Method Nullness in Java. In Proceedings of the 17th International Working Conference on Source Code Analysis and Manipulation, SCAM 2017, 2017. Details.


Null pointer exceptions are common bugs in Java projects. Previous research has shown that dereferencing the results of method calls is the main source of these bugs, as developers do not anticipate that some methods return null. To make matters worse, we find that whether a method returns null or not (nullness), is rarely documented. We argue that method nullness is a vital piece of information that can help developers avoid this category of bugs. This is especially important for external APIs where developers may not even have access to the code. In this paper, we study the method nullness of Apache Lucene, the de facto standard library for text processing in Java. Particularly, we investigate how often the result of each Lucene method is checked against null in Lucene clients. We call this measure method nullability, which can serve as a proxy for method nullness. Analyzing Lucene internal and external usage, we find that most methods are never checked for null. External clients check more methods than Lucene checks internally. Manually inspecting our dataset reveals that some null checks are unnecessary. We present an IDE plugin that complements existing documentation and makes up for missing documentation regard- ing method nullness and generates nullness annotations, so that static analysis can pinpoint potentially missing or unnecessary null checks.

Posted by scg at 15 August 2017, 5:15 pm link
Last changed by admin on 21 April 2009