We studied the characteristics of the preconditions that were correctly-mined, incorrectly-mined and missing from our approach.
Correctly Mined Preconditions
For the APIs in our dataset, correctly mined preconditions falls into three categories: null comparison, primitive comparison and method invocation. The first one contains simple preconditions comparing arguments with null such as ARG!=null. The preconditions in the second category contains arguments of primitive types comparing to constants or other primitive arguments such as ARG1≥0 and ARG1≤ARG2. The last one containing method calls, on receivers such as !Receiver.hasNext() or on arguments such as !ARG.isEmpty() or on both. Table 1 shows the numbers of preconditions for each category correctly mined from the base approach and the additional ones from our approach using implicit beliefs. The numbers in parentheses are the percentages over all expected preconditions in the corresponding category.
Incorrectly Mined Preconditions
We have examined the incorrectly mined preconditions to find out the reason behind the occurrences of such conditions. Table 2 shows these categories of incorrectly mined preconditions for different libraries.
The first category contains incorrectly-mined preconditions which are stronger than required. For example, API parse(InputSource, DefaultHandler) in class javax.xml.parsers.SAXParser parses the InputSource parameter using the specified DefaultHandler parameter. It makes sense from usage point of view to not pass an null default handler. Through using implicit belief, the tool will also mine the precondition that the second parameter cannot be null. However, that condition is not required by API and, thus, introduces the incorrectly mined precondition. These cases increases the number of stronger preconditions compared to the base usage-based mining approach and, therefore, increases the number of preconditions incorrectly mined by our approach. The libraries CHART, DATA and SWING resulted in mining more stronger conditions compared to base usage based mining approach.
We also observed incorrectly-mined preconditions which are weaker than required. For example, the mined preconditions is ARG!=-1 while the required one is ARG≥0. However, all of these weaker preconditions came from the explicit guard conditions present in the code instead of from implicit beliefs. Another major type of incorrect conditions in our result is the project-specific conditions. To some extent, they are also stronger than needed. However, we put them in a separate category because these mined preconditions are only frequent in certain projects. As some APIs do not have rich use cases across multiple projects, many project-specific conditions were considered as preconditions for these APIs. Result on XML library suffers from this the most, we examined and found that most of the call sites in the dataset calls the APIs for a document, until reaching the end of the document. Hence conditions such as hasnext() or !isEndDocument() is not part of specification for most of the APIs of this library, but are frequently present before the calls of the APIs because of the access pattern. Despite that, our implicit belief from local exception component successfully removed conditions guarding project-specific exception and lowered the number of incorrect preconditions from project-specific conditions.
Missing Preconditions
Although our approach was able to detect more preconditions through implicit belief compared to existing usage based mining approach, we still miss preconditions. We have analyzed the missing classes of preconditions that our approach was unable to find given the dataset we have used for 7 libraries of interest. We found that we did not miss any preconditions that the base approach could mine. We have mainly observed three categories of missing preconditions shown in Table 3.