Are code examples on an online Q&A forum reliable?: a study of API misuse on stack overflow
Open accessThe DOI matches its Crossref record; 34 of the 34 references it cites were found in a registry or an index.
Abstract
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.
Overview
The claims and statistics of this paper haven’t been checked yet.
Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.
Integrity signals
Registry
Cites
Statistics
Verification
Claims the paper makes
The claims and statistics of this paper haven’t been checked yet.
Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.
Self-check
Percentages, sums and reported differences re-computed from the paper’s own numbers.
The self-check needs the paper’s full text.
Citations
Cites
(2005) · PubMed · Cited by 7,011
de Moura, L., & Bjørner, N. (2008) · Lecture Notes in Computer Science · doi:10.1007/978-3-540-78800-3_24 · Cited by 6,595 · cited 2×
“In order to accurately estimate the frequency of unique guard conditions, ExampleCheck uses a SMT solver, Z3 [6], to check the semantic equivalence of guard conditions, instead of considering the syntactic similarity between them only.”
MethodFormal Concept Analysis: Mathematical Foundations
Ganter, B., Wille, R., & Franzke, C. (1998) · CERN Document Server (European Organization for Nuclear Research) · Cited by 4,245
Dynamically discovering likely program invariants to support program evolution
Ernst, M. D., Cockrell, J., Griswold, W. G., & Notkin, D. (2001) · IEEE Transactions on Software Engineering · doi:10.1109/32.908957 · Cited by 1,050
Allen, F. E. (1970) · ACM SIGPLAN Notices · doi:10.1145/390013.808479 · Cited by 738
Weiser, M. (1981) · doi:10.5555/800078.802557 · Cited by 695
Ammons, G., Bodík, R., & Larus, J. R. (2002) · Proceedings of the 29th ACM SIGPLAN-SIGACT symposium on Principles of programming languages · doi:10.1145/503272.503275 · Cited by 665 · cited 1×
“Many other specification mining techniques are dedicated to inferring temporal properties of API calls [3, 9, 11, 21, 22, 36].”
BackgroundEfficiently Using Prefix-trees in Mining Frequent Itemsets.
Grahne, G., & Zhu, J. (2003) · Cited by 457
Li, Z., & Zhou, Y. (2005) · Proceedings of the 10th European software engineering conference held jointly with 13th ACM SIGSOFT international symposium on Foundations of software engineering · doi:10.1145/1081706.1081755 · Cited by 428 · cited 1×
“Several techniques [17, 18, 29] model programs as item sets and infer pairwise programming rules using frequent itemset mining [14], which does not consider temporal ordering or guard conditions of API calls.”
MethodMAPO: Mining and Recommending API Usage Patterns
Zhong, H., Xie, T., Zhang, L., Pei, J., & Mei, H. (2009) · Lecture Notes in Computer Science · doi:10.1007/978-3-642-03013-0_15 · Cited by 410 · cited 1×
“Computing the common subsequence is widely practiced in the literature of API usage mining [27, 28, 34, 40] and has the benefit of filtering out API calls pertinent to only a few outlier examples.”
BackgroundParseweb: a programmer assistant for reusing open source code on the web
Thummalapenta, S., & Xie, T. (2007) · Proceedings of the twenty-second IEEE/ACM international conference on Automated software engineering · doi:10.1145/1321631.1321663 · Cited by 391 · cited 1×
“Computing the common subsequence is widely practiced in the literature of API usage mining [27, 28, 34, 40] and has the benefit of filtering out API calls pertinent to only a few outlier examples.”
BackgroundWhat makes a good code example?: A study of programming Q&A in StackOverflow
Nasehi, S. M., Sillito, J., Maurer, F., & Burns, C. (2012) · 2012 28th IEEE International Conference on Software Maintenance (ICSM) · doi:10.1109/icsm.2012.6405249 · Cited by 287 · cited 3×
“Including code and detailed step-by-step explanations is the key factor in highly voted Stack Overflow posts [19].”
BackgroundMethodInfluentialStack Overflow Considered Harmful? The Impact of Copy&Paste on Android Application Security
Fischer, F., Bottinger, K., Xiao, H., Stransky, C., Acar, Y., Backes, M., & Fahl, S. (2017) · 2017 IEEE Symposium on Security and Privacy (SP) · doi:10.1109/sp.2017.31 · Cited by 280
Detecting object usage anomalies
Wasylkowski, A., Zeller, A., & Lindig, C. (2007) · Proceedings of the the 6th joint meeting of the European software engineering conference and the ACM SIGSOFT symposium on The foundations of software engineering · doi:10.1145/1287624.1287632 · Cited by 272 · cited 2×
“Many other specification mining techniques are dedicated to inferring temporal properties of API calls [3, 8, 10, 19, 20, 35].”
BackgroundBoa: A Language and Infrastructure for Analyzing Ultra-Large-Scale Software Repositories
Dyer, R., Nguyen, H. A., Rajan, H., & Nguyen, T. N. (2013) · Cited by 254
Self-citationSubramanian, S., Inozemtseva, L., & Holmes, R. (2014) · Proceedings of the 36th International Conference on Software Engineering · doi:10.1145/2568225.2568313 · Cited by 239 · cited 2×
“ExampleCheck leverages a state-of-the-art partial program parsing and type resolution technique to handle these incomplete snippets, whose accuracy of API resolution is reported to be 97% [24].”
BackgroundMethodHow developers search for code: a case study
Sadowski, C., Stolee, K. T., & Elbaum, S. (2015) · Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering · doi:10.1145/2786805.2786855 · Cited by 238 · cited 2×
“A case study at Google shows that developers issue an average of 12 code search queries per weekday [24].”
BackgroundFrequent Closed Sequence Mining without Candidate Maintenance
Wang, J., Han, J., & Li, C. (2007) · IEEE Transactions on Knowledge and Data Engineering · doi:10.1109/tkde.2007.1043 · Cited by 212 · cited 1×
“Given a set of structured call sequences from Phase 1, Maple finds common subsequences using BIDE [35].”
MethodMining succinct and high-coverage API usage patterns from source code
Wang, J., Dang, Y., Zhang, H., Chen, K., Xie, T., & Zhang, D. (2013) · 2013 10th Working Conference on Mining Software Repositories (MSR) · doi:10.1109/msr.2013.6624045 · Cited by 189 · cited 2×
“Computing the common subsequence is widely practiced in the literature of API usage mining [27, 28, 34, 40] and has the benefit of filtering out API calls pertinent to only a few outlier examples.”
BackgroundStatic specification inference using predicate mining
Ramanathan, M. K., Grama, A. Y., & Jagannathan, S. (2007) · ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI) · doi:10.1145/1250734.1250749 · Cited by 126 · cited 1×
“To our best knowledge, Ramanathan et al. [23] and Nguyen et al. [20]”
BackgroundRecovering traceability links between an API and its learning resources
Dagenais, B., & Robillard, M. P. (2012) · doi:10.5555/2337223.2337230 · Cited by 120
Gruska, N., Wasylkowski, A., & Zeller, A. (2010) · International Symposium on Software Testing and Analysis · doi:10.1145/1831708.1831723 · Cited by 95 · cited 2×
“extract call sequences from programs and perform formal concept analysis [11] to infer pairwise temporal properties of API calls [14].”
BackgroundMining preconditions of APIs in large-scale code corpus
Nguyen, H. A., Dyer, R., Nguyen, T. N., & Rajan, H. (2014) · ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE) · doi:10.1145/2635868.2635924 · Cited by 94 · cited 3×
“Compared with prior work [18], ExampleCheck is capable of proving the semantic equivalence of arbitrary predicates regardless of their syntactic similarity.”
BackgroundMethodInfluentialSelf-citationStack Overflow: A code laundering platform?
An, L., Mlouki, O., Khomh, F., & Antoniol, G. (2017) · IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER) · doi:10.1109/saner.2017.7884629 · Cited by 81 · cited 1×
“investigate copyright issues between Stack Overflow and GitHub [4] and find a large number of potential license violations.”
BackgroundAPI deprecation: a retrospective analysis and detection method for code examples on the web
Zhou, J., & Walker, R. J. (2016) · ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE) · doi:10.1145/2950290.2950298 · Cited by 81
From Query to Usable Code: An Analysis of Stack Overflow Code SnippetsPreprint
Yang, D., Hussain, A., & Lopes, C. V. (2016) · arXiv (Cornell University) · doi:10.48550/arxiv.1605.04464 · Cited by 80 · cited 2×
“Both Sub-ramanian et al. [25] and Yang et al. [39] show that the majority of code examples on Stack Overflow are free-standing program statements that cannot be accepted by compilers.”
BackgroundAmann, S., Nadi, S., Nguyen, H. A., Nguyen, T. N., & Mezini, M. (2016) · International Conference on Mining Software Repositories (MSR) · doi:10.1145/2901739.2903506 · Cited by 80 · cited 1×
“The rest 30 APIs come from an API misuse benchmark, MUBench [2], after we exclude those patterns without corresponding SO posts and those that cannot be generalized to other projects.”
BackgroundArchetypal Internet-Scale Source Code Searching
Umarji, M., Sim, S. E., & Lopes, C. V. (2008) · IFIP International Federation for Information Processing/IFIP · doi:10.1007/978-0-387-09684-1_21 · Cited by 75
Archetypal Internet-Scale Source Code Searching
Umarji, M., & Sim, S. E. (2013) · Springer eBooks · doi:10.1007/978-1-4614-6596-6_3 · Cited by 74 · cited 1×
“Programmers often resort to online code examples during software development [24, 32].”
BackgroundFrom query to usable code: an analysis of stack overflow code snippets
Yang, D., Hussain, A., & Lopes, C. V. (2016) · Proceedings of the 13th International Conference on Mining Software Repositories · doi:10.1145/2901739.2901767 · Cited by 74 · cited 2×
“Both Sub-ramanian et al. [25] and Yang et al. [39] show that the majority of code examples on Stack Overflow are free-standing program statements that cannot be accepted by compilers.”
BackgroundMaking sense of online code snippets
Subramanian, S., & Holmes, R. (2013) · International Conference on Mining Software Repositories (MSR) · doi:10.1109/msr.2013.6624012 · Cited by 67 · cited 3×
“Previous studies have shown that online code snippets are often unparsable [23, 37] and contain ambiguous API elements [5] due to the incompleteness of these snippets.”
BackgroundUnderstanding Stack Overflow Code Fragments
Treude, C., & Robillard, M. P. (2017) · 2017 IEEE International Conference on Software Maintenance and Evolution (ICSME) · doi:10.1109/icsme.2017.24 · Cited by 56 · cited 2×
“Previous studies have also investigated the quality of online code examples in terms of compilability [23, 37], unchecked obsolete usage [39], and comprehension issues [29].”
BackgroundVisualizing API Usage Examples at Scale
Glassman, E. L., Zhang, T., Hartmann, B., & Kim, M. (2018) · Proceedings of the 2018 CHI Conference on Human Factors in Computing Systems · doi:10.1145/3173574.3174154 · Cited by 48
Self-citationUpadhyaya, G., & Rajan, H. (2018) · ACM/IEEE International Conference on Software Engineering: Companion Proceedings (ICSE-Companion) · doi:10.1145/3180155.3180252 · Cited by 8 · cited 1×
“By leveraging an ultra-large-scale software mining infrastructure [7, 31], ExampleCheck efficiently searches over GitHub and retrieves an average of 55144 code snippets for a given API within 10 minutes.”
MethodSelf-citation
Cited by
Using an LLM to Help With Code Understanding
Nam, D., Macvean, A., Hellendoorn, V., Vasilescu, B., & Myers, B. (2024) · Proceedings of the IEEE/ACM 46th International Conference on Software Engineering · doi:10.1145/3597503.3639187 · Cited by 487
Bugs in Large Language Models Generated Code: An Empirical Study
Tambon, F., Dakhel, A. M., Nikanjam, A., Khomh, F., Desmarais, M. C., & Antoniol, G. (2024) · arXiv · doi:10.48550/arxiv.2403.08937 · Cited by 70
Understanding How Programmers Can Use Annotations on Documentation
Horvath, A., Liu, M. X., Hendriksen, R., Shannon, C., Paterson, E., Jawad, K., Macvean, A., & Myers, B. A. (2022) · CHI Conference on Human Factors in Computing Systems · doi:10.1145/3491102.3502095 · Cited by 26
“However, there is signifcant evidence that APIs are often difcult to use [19, 42, 50], which can cause APIs to be used incorrectly, resulting in bugs and sometimes signifcant security problems [22, 58].”
BackgroundEnabling Data-Driven API Design with Community Usage Data: A Need-Finding Study
Zhang, T., Hartmann, B., Kim, M., & Glassman, E. L. (2020) · Proceedings of the 2020 CHI Conference on Human Factors in Computing Systems · doi:10.1145/3313831.3376382 · Cited by 25
“Making mistakes in API usage could lead to severe program failures such as runtime exceptions [60] and security vulnerabilities [21, 18, 16].”
BackgroundMethodInfluentialSelf-citationMARBLE: Mining for Boilerplate Code to Identify API Usability Problems
Nam, D., Horvath, A., Macvean, A., Myers, B., & Vasilescu, B. (2019) · 2019 34th IEEE/ACM International Conference on Automated Software Engineering (ASE) · doi:10.1109/ase.2019.00063 · Cited by 19
Metadata
- Authors
- Zhang, T., Upadhyaya, G., Reinhardt, A., Rajan, H., & Kim, M.
- Venue
- Proceedings of the 40th International Conference on Software Engineering
- Publisher
- ACM
- Published
- 2018-05-27
- Pages
- 886-896
- ISSN
- 0270-5257 (ISSN-L)
- OpenAlex
- W2794992746
- Cited by
- 167
- References
- 34
- FWCI
- 15.95
- Type
- conference paper
- Language
- en
- Open access
- bronze
About these checks
Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.
Statistics and arithmetic are recomputed, not judged.
Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.
What counts as a claim ›How we measure confidence ›How we check this ›
Are you an author, or do you see a problem with this page? Request a review
Data sources
Bibliographic data: Semantic Scholar, OpenAlex, Crossref.
Contains information from the Semantic Scholar Academic Graph Datasets, made available under the ODC Attribution License (ODC-BY 1.0).
Semantic Scholar’s data is described in: Kinney, R., et al. (2023). The Semantic Scholar Open Data Platform. arXiv:2301.10140.