一句话:通过 ExampleCheck 挖掘 GitHub API 使用模式,发现 Stack Overflow 上 31% 的帖子可能存在 API 误用。
程序员常借助 Stack Overflow 等在线问答论坛学习 API,但其中的代码示例是否可靠尚缺系统证据。本文对 Stack Overflow 上 API 误用的普遍性与严重性进行实证研究,并提出 ExampleCheck:一个 API 使用挖掘框架,先从 GitHub 超过 38 万个 Java 仓库中提取 API 使用模式,再据此检测问答帖子中的潜在违规。作者分析 217,818 个帖子,发现 31% 可能存在会导致程序崩溃、资源泄漏等意外行为的 API 误用。误用主要源于缺失控制结构、API 调用缺失或顺序错误、守卫条件错误。即便被采纳或高赞的答案,在 API 误用方面也不一定更可靠。研究呼吁补充策展示例中通常未展示的替代 API 用法信息。
Programmers often consult an online Q&A forum such as Stack Overflow to learn new APIs. This paper presents an empirical study on the prevalence and severity of API misuse on Stack Overflow. To reduce manual assessment effort, we design ExampleCheck, an API usage mining framework that extracts patterns from over 380K Java repositories on GitHub and subsequently reports potential API usage violations in Stack Overflow posts. We analyze 217,818 Stack Overflow posts using ExampleCheck and find that 31% may have potential API usage violations that could produce unexpected behavior such as program crashes and resource leaks. Such API misuse is caused by three main reasons---missing control constructs, missing or incorrect order of API calls, and incorrect guard conditions. Even the posts that are accepted as correct answers or upvoted by other programmers are not necessarily more reliable than other posts in terms of API misuse. This study result calls for a new approach to augment Stack Overflow with alternative API usage details that are not typically shown in curated examples.
@inproceedings{paperbot4482,
title = {Are code examples on an online Q&A forum reliable?},
author = {Tianyi Zhang and Ganesha Upadhyaya and Anastasia Reinhardt and Hridesh Rajan and Miryung Kim},
booktitle = {ICSE},
year = {2018},
doi = {10.1145/3180155.3180260}
}