[Paper Review] Can ChatGPT replace StackOverflow? A Study on Robustness and Reliability of Large Language Model Code Generation
This paper introduces RobustAPI, a benchmark to evaluate the reliability and robustness of code generated by large language models (LLMs), focusing on API misuse in Java. Despite functional correctness, GPT-4 exhibits a 62% API misuse rate, highlighting critical risks in real-world software when using LLM-generated code without verification.
Recently, the large language models (LLMs) have shown extraordinary ability in understanding natural language and generating programming code. It has been a common practice of software engineers to consult LLMs when encountering coding questions. Although efforts have been made to avoid syntax errors and align the code with the intended semantics, the reliability and robustness of the code generationfrom LLMs have not yet been thoroughly studied. The executable code is not equivalent to the reliable and robust code, especially in the context of real-world software development. The misuse of APIs in the generated code could lead to severe problem, such as resource leaks, program crashes. To make things worse, the users of LLM code generation services are actually the developers that are most vulnerable to these code that seems right -- They are always novice developers that are not familiar with the APIs that LLMs generate code for them. Therefore, they could hardly tell the misuse in the code generated by LLMs, which further facilitates the incorrect code applied in real-world software. Existing code evaluation benchmark and datasets focus on crafting small tasks such as programming questions in coding interviews, which however deviates from the problem that developers would ask LLM for real-world coding help. To fill the missing piece, in this work, we propose a dataset RobustAPI for evaluating the reliability and robustness of code generated by LLMs. We collect 1208 coding questions from StackOverflow on 24 representative Java APIs. We summarize thecommon misuse patterns of these APIs and evaluate them oncurrent popular LLMs. The evaluation results show that evenfor GPT-4, 62% of the generated code contains API misuses,which would cause unexpected consequences if the code isintroduced into real-world software.
Motivation & Objective
- To address the lack of evaluation frameworks that assess the reliability and robustness of LLM-generated code beyond functional correctness.
- To identify and quantify common API misuse patterns in real-world software development scenarios.
- To develop a benchmark that reflects actual developer queries from Stack Overflow, focusing on widely used Java APIs.
- To evaluate the effectiveness of prompting strategies such as in-context learning and API rule injection in reducing misuse.
- To open-source the dataset and evaluation framework to enable future research on reliable code generation.
Proposed method
- The authors collected 1,208 real coding questions from Stack Overflow related to 18 representative Java APIs.
- They formalized correct API usage patterns as structured call sequences using abstract syntax trees (ASTs) to define proper usage sequences.
- A custom evaluator was built to analyze generated code by comparing its AST structure against expected usage patterns.
- The benchmark was evaluated on four LLMs: GPT-3.5, GPT-4, Llama-2, and Vicuna-1.5 under zero-shot and one-shot prompting settings.
- The study used both functional correctness and API misuse detection as evaluation metrics, with misuse defined as violations of structured call sequences.
- Temperature and prompt engineering (e.g., adding API rules) were tested to assess their impact on reducing misuse.
Experimental results
Research questions
- RQ1How prevalent is API misuse in LLM-generated code, even when the code is syntactically correct and functionally aligned with user intent?
- RQ2Can in-context learning with relevant examples significantly reduce API misuse rates in LLM-generated code?
- RQ3Does injecting explicit API usage rules into prompts improve the reliability of generated code compared to few-shot prompting?
- RQ4Which Java APIs are most prone to misuse by LLMs, and what are the dominant misuse patterns?
- RQ5To what extent do temperature settings and model architecture influence the likelihood of API misuse?
Key findings
- GPT-4, despite being the most advanced model tested, still exhibits a 62% API misuse rate in generated code, indicating widespread reliability issues.
- Even with one-shot relevant examples, GPT-3.5 maintains a 38.56% misuse rate, showing limited improvement from few-shot prompting.
- Injecting API usage rules into prompts did not significantly reduce misuse rates, with GPT-3.5 showing a 65.01% misuse rate under this setting.
- Compilation failure rates were lowest for GPT-4 (<10%), while GPT-3.5 had higher rates, especially at higher temperature settings.
- The Android API Activity.setContentView had the lowest misuse rate across all models, suggesting some APIs are more predictable for LLMs.
- The most common misuse patterns include missing exception handling, improper resource closing, and incorrect method sequence ordering.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.