A Method-Level Defect Prediction Approach Based on Structural Features of Method-Calling Network

Fengyu Yang, Haoming Xu, Peng Xiao, Fa Zhong, Guangdong ZengIEEE Access 2023

Abstract

Software defect prediction is a vital tool for optimizing testing resources by identifying high-risk components before deployment. However, most existing models operate at a coarse granularity, such as the class or file level, which often leaves developers with too much code to inspect. This paper, published in IEEE Access, introduces a novel method-level defect prediction approach that treats software as a "Method-Calling Network" (MCN). By integrating traditional code metrics with structural features derived from graph theory and network embeddings (node2vec), the proposed model significantly enhances prediction accuracy across various open-source projects.

Introduction: The Granularity Gap

In the software development lifecycle, testing is often the most time-consuming phase. Defect prediction models aim to alleviate this bottleneck by flagging modules likely to contain bugs. While class-level prediction is common, it lacks the precision needed for efficient debugging. Method-level prediction offers the necessary granularity but presents a greater challenge due to the limited information available within a single method's code.

Traditional models rely heavily on static code metrics, such as lines of code or cyclomatic complexity. The authors of this study argue that these metrics ignore the "social" context of a method—how it interacts with other parts of the system. A simple method might be a critical failure point if it serves as a central hub in the program's execution flow.

Modeling Software as a Network

The core innovation of this research is the construction of a Method-Calling Network (MCN). By parsing Java bytecode, the researchers create a directed graph where each node represents a method and each edge represents a call from one method to another. This transformation allows the application of advanced graph-mining techniques to software analysis.

Mapping Java source code to a Method-Calling Network (MCN).

As shown in the figure above, the structural relationships between methods (a) are explicitly captured in the resulting graph (b). This network representation provides a rich source of data regarding the dependencies and importance of individual methods within the larger system.

The NENCM Model: A Multi-Feature Approach

The researchers developed the NENCM model, which stands for Network Embedding, Network Metrics, and Code Metrics. This model utilizes three distinct categories of features:

  1. Traditional Code Metrics: 20 standard metrics, including McCabe’s complexity and Halstead measures, to capture the internal logic of the method.
  2. Network Metrics: 53 graph-theory statistics that describe a node's position in the network. These include "Ego" metrics (local properties like degree) and "Global" metrics (centrality measures like Betweenness).
  3. Network Embedding (node2vec): The model uses the node2vec algorithm to learn latent structural patterns. By converting the graph structure into low-dimensional vectors, the model can identify complex relational features that manual metrics might overlook.

These features are processed using a Random Forest classifier. To address the inherent class imbalance in software data (where non-defective methods far outnumber defective ones), the team applied random oversampling during the training phase.

Experimental Results

The approach was validated using 13 diverse open-source Java projects, including EclEmma, HtmlUnit, and Jmol. The results demonstrated that structural features are powerful predictors of defects:

  • Significant Performance Boost: The NENCM model outperformed traditional baselines across all metrics. Notably, the Matthews Correlation Coefficient (MCC)—a robust measure for imbalanced datasets—showed improvements ranging from 13% to a staggering 178.4%.
  • Area Under Curve (AUC): The model achieved AUC improvements between 2.5% and 6.7% over existing methods.
  • Effort-Aware Efficiency: In simulations where testers only had the resources to check 20% of the code, the NENCM model consistently identified a higher proportion of total defects compared to models using only code metrics.

Conclusion and Future Directions

This research highlights that how a method is connected is just as important as what it contains. By leveraging the structural information inherent in method-calling networks, developers can more accurately pinpoint risky code at a granular level.

While the results are promising, the authors note that the current model is specific to Java and does not yet incorporate semantic features (the actual "meaning" of the code text). Future work will explore combining these structural insights with Natural Language Processing (NLP) and investigating the model's performance in cross-project prediction scenarios.

Summary updated

BibTeX
@article{yang2023method,
  author = {Fengyu Yang and Haoming Xu and Peng Xiao and Fa Zhong and Guangdong Zeng},
  title = {{A Method-Level Defect Prediction Approach Based on Structural Features of Method-Calling Network}},
  journal = {IEEE Access},
  year = {2023},
  doi = {10.1109/access.2023.3239266},
}
Figure