一句话:提出 KGAMD,从 API 文档构建细粒度 API 约束知识图谱,并直接据此检测多种 API 误用。
API 通常带有使用约束,违反约束(API 误用)会引发严重问题。现有方法从代码库挖掘频繁使用模式,假设偏离最常见用法即为误用,但使用模式与真实 API 约束在全面性、可解释性和最佳实践上存在知识鸿沟。本文提出 KGAMD,直接基于 API 约束知识检测误用:用开放信息抽取从 API 参考文档构建细粒度约束知识图谱,显式建模调用顺序与条件检查关系,并用返回条件与异常触发丰富返回和抛出关系。基于该图谱,KGAMD 检测缺失调用、缺失条件检查和缺失异常处理三类误用,而现有检测器多只关注缺失调用。定量评估与用户研究显示其能帮助开发者避免和调试 API 误用。
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
DOI 原文 ·
@inproceedings{paperbot6418,
title = {KGAMD: an API-misuse detector driven by fine-grained API-constraint knowledge graph},
author = {Xiaoxue Ren and Xinyuan Ye and Zhenchang Xing and Xin Xia and Xiwei Xu and Liming Zhu and Jianling Sun},
booktitle = {FSE},
year = {2021},
doi = {10.1145/3468264.3473112}
}