Predicting Line-Level Defects by Capturing Code Contexts with Hierarchical Transformers

Parvez Mahbub,Mohammad Masudur Rahman
2023-12-19
Abstract:Software defects consume 40% of the total budget in software development and cost the global economy billions of dollars every year. Unfortunately, despite the use of many software quality assurance (SQA) practices in software development (e.g., code review, continuous integration), defects may still exist in the official release of a software product. Therefore, prioritizing SQA efforts for the vulnerable areas of the codebase is essential to ensure the high quality of a software release. Predicting software defects at the line level could help prioritize the SQA effort but is a highly challenging task given that only ~3% of lines of a codebase could be defective. Existing works on line-level defect prediction often fall short and cannot fully leverage the line-level defect information. In this paper, we propose Bugsplorer, a novel deep-learning technique for line-level defect prediction. It leverages a hierarchical structure of transformer models to represent two types of code elements: code tokens and code lines. Unlike the existing techniques that are optimized for file-level defect prediction, Bugsplorer is optimized for a line-level defect prediction objective. Our evaluation with five performance metrics shows that Bugsplorer has a promising capability of predicting defective lines with 26-72% better accuracy than that of the state-of-the-art technique. It can rank the first 20% defective lines within the top 1-3% suspicious lines. Thus, Bugsplorer has the potential to significantly reduce SQA costs by ranking defective lines higher.
Software Engineering,Artificial Intelligence
What problem does this paper attempt to address?
### Problems the Paper Attempts to Solve This paper aims to address the issue of defect prediction in the software development process, particularly at the code line level. Specifically, the paper tackles the following key problems: 1. **Limitations of Existing Methods**: - Existing models cannot adequately represent code elements (such as code tokens and code lines) because they only focus on unidirectional information and cannot capture both preceding and succeeding context information simultaneously. - Existing models optimize defect prediction at the file level during training, rather than at the line level, making it difficult for them to capture local defect context. 2. **Proposed New Method**: - A new deep learning technique called Bugsplorer is proposed, which uses a hierarchical Transformer model to estimate the attention values of two types of code elements (code tokens and code lines). - Bugsplorer can capture both preceding and succeeding context information of code elements simultaneously and is directly optimized for line-level defect prediction. 3. **Experimental Validation**: - Bugsplorer was evaluated using two benchmark datasets (Defectors and LineDP), and the results showed that it improved the accuracy of line-level defect prediction by 26% to 72% compared to existing state-of-the-art techniques, and significantly reduced the effort required to locate defects. Through the above research, Bugsplorer is expected to significantly reduce the cost of Software Quality Assurance (SQA) and improve the efficiency of defect detection.