Abstract
This research introduces a novel deep learning framework for software defect prediction that leverages the inherent hierarchical structure of source code. By employing Tree-structured Long Short-Term Memory (Tree-LSTM) networks to process Abstract Syntax Trees (ASTs), the model automatically extracts complex syntactic and semantic features. Experimental results demonstrate that this approach significantly outperforms traditional defect prediction methods relying on manual feature engineering, achieving superior recall and cross-project generalizability.
Introduction
Software defects pose significant risks to business continuity and safety. Predicting bug-prone code allows development teams to optimize resource allocation during testing and code review. However, traditional defect prediction is hampered by a reliance on "hand-crafted" features—such as lines of code or cyclomatic complexity—which often fail to capture the deep structural logic of a program. This paper addresses the "feature engineering" bottleneck by proposing a model that learns directly from the code's structure, treating it as a hierarchy rather than a flat string of text.
Methodology
The proposed system treats source code as a hierarchy to capture the logical flow of the program. The process involves several key stages:
- AST Parsing: Source files are converted into Abstract Syntax Trees (ASTs). This removes "noise" like comments and formatting while preserving the logical structure of the program.
- Node Embedding (ast2vec): Each AST node (e.g., a
WhileStmtorVariableDeclarator) is mapped to a continuous vector space. This allows the model to recognize that semantically similar elements should be "close" to each other mathematically. - Tree-LSTM Architecture: The core model uses a Tree-structured LSTM to aggregate information from the leaves of the AST up to the root. Unlike standard LSTMs, this architecture is uniquely suited to capturing long-range dependencies within the code's logic.
- Classification: The final vector representing the entire file is fed into a classifier (such as Random Forest) to predict if the file is "defective" or "clean."
Experimental Setup
The model was evaluated using two primary datasets to test its versatility:
- Samsung Dataset: Comprising 8,118 C-language files from industrial projects (including Tizen OS), with labels derived from internal static analysis tools.
- PROMISE Repository: A standard public benchmark containing 10 Java projects (e.g., Lucene, Ant, Camel), used to facilitate comparison with existing state-of-the-art research.
Results and Discussion
The tree-based model demonstrated substantial improvements over baseline methods across multiple metrics, as visualized in Figure 6.
- Superior Recall: On the PROMISE benchmark, the model achieved an average recall of 0.86, representing a 23% improvement over previous Deep Belief Network (DBN) models. High recall is critical in defect prediction to ensure as many bugs as possible are identified.
- Industrial Performance: On the Samsung dataset, the model reached an Area Under the Curve (AUC) of 0.98 when utilized with a Random Forest classifier, showing high accuracy on real-world industrial code.
- Cross-Project Generalizability: The model remained effective even when trained on one project and tested on a completely different one. This suggests that the structural patterns of "buggy code" generalize across different software applications.
Conclusion
By aligning neural network architecture with the natural tree structure of source code, this approach moves beyond shallow manual metrics toward deep semantic understanding. While the current model operates at the file level and shows some trade-offs between precision and recall, it sets a new benchmark for automated defect prediction. Future work will focus on increasing prediction granularity to the method or line level and expanding support to additional programming languages like PHP and C++.
Summary updated