Application Programming Interfaces (APIs) typically come with usage constraints. The violations of these constraints (i.e. API misuses) can cause significant problems in software development. Existing methods mine frequent API usage patterns from codebase to detect API misuses. They make a naive assumption that API usage that deviates from the most-frequent API usage is a misuse. However, there is a big knowledge gap between API usage patterns and API usage constraints in terms of comprehensiveness, explainability and best practices. Inspired by this, we propose a novel approach named KGAMD (API-Misuse Detector Driven by Fine-Grained API-Constraint Knowledge Graph) that detects API misuses directly against the API constraint knowledge, rather than API usage pat-terns. We first construct a novel API-constraint knowledge graph from API reference documentation with open information extraction methods. This knowledge graph explicitly models two types of API-constraint relations (call-order and condition-checking) and enriches return and throw relations with return conditions and exception triggers. Then, we develop the KGAMD tool that utilizes the knowledge graph to detect API misuses. There are three types of frequent API misuses we can detect - missing calls, missing condition checking and missing exception handling, while existing detectors mostly focus on only missing calls. Our quantitative evaluation and user study demonstrate that our KGAMD is promising in helping developers avoid and debug API misuses Demo Video: https://www.youtube.com/watch?v=TN4LtHJ-494 IntelliJ plug-in: https://github.com/goodchar/KGAMD
[1]
Tao Xie,et al.
Alattin: Mining Alternative Patterns for Detecting Neglected Conditions
,
2009,
2009 IEEE/ACM International Conference on Automated Software Engineering.
[2]
Tung Thanh Nguyen,et al.
Recommending API Usages for Mobile Apps with Hidden Markov Model
,
2015,
2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE).
[3]
Hoan Anh Nguyen,et al.
Graph-based mining of multiple object usage patterns
,
2009,
ESEC/FSE '09.
[4]
Yuanyuan Zhou,et al.
/*icomment: bugs or bad comments?*/
,
2007,
SOSP.
[5]
Mira Mezini,et al.
A Systematic Evaluation of Static API-Misuse Detectors
,
2017,
IEEE Transactions on Software Engineering.
[6]
Mira Mezini,et al.
MUBench: A Benchmark for API-Misuse Detectors
,
2016,
2016 IEEE/ACM 13th Working Conference on Mining Software Repositories (MSR).
[7]
Jiamou Sun,et al.
Improving API Caveats Accessibility by Mining API Caveats Knowledge Graph
,
2018,
2018 IEEE International Conference on Software Maintenance and Evolution (ICSME).
[8]
Monika Eisenhower,et al.
Elements Of Survey Sampling
,
2016
.