Software defect prediction with semantic and structural information of codes based on Graph Neural Networks

Most defect prediction methods consider a series of traditional manually designed static code metrics. However, only using these hand-crafted features is impractical. Some researchers use the Convolutional Neural Network (CNN) to capture the potential semantic information based on the program’s Syntax Trees (ASTs). In recent years, leveraging the dependency relationships between software modules to construct a software network and using network embedding models to capture the structural information have been helpful in defect prediction. This paper simultaneously takes the semantic and structural information into account and proposes a method called CGCN. This study aims to validate the feasibility and performance of the proposed method in software defect prediction. Abstract Syntax Trees and a Class Dependency Network (CDN) are first generated based on the source code. For ASTs, symbolic tokens are extracted and encoded into vectors. The numerical vectors are then used as input to the CNN to capture the semantic information. For CDN, a Graph Convolutional Network (GCN) is used to learn the structural information of the network automatically. Afterward, the learned semantic and structural information are combined with different weights. Finally, we concatenate the learned features with traditional hand-crafted features to train a classifier for more accurate defect prediction. The proposed method outperforms the state-of-the-art defect prediction models for both within-project prediction (including within-version and cross-version) and cross-project prediction on 21 open-source projects. In general, within-version prediction achieves better performance in the three prediction tasks. The proposed method of combining semantic and structural information can improve the performance of software defect prediction. • A novel defect prediction model (CGCN), which combines CNN and GCN. The proposed model can extract the semantic information from the ASTs of the source codes, as well as the structural information between modules from the software network. Therefore, the defect prediction performance is improved. • Different weight parameters are used for semantic and structural features, in order to make them play different contributions in different tasks and improve the model generalization ability. • The efficiency of CGCN is evaluated on seven Java open-source projects (each project selects three versions, with a total of 21 datasets) and three tasks (withinversion defect prediction, cross-version defect prediction and cross-project defect prediction). The results demonstrate that the CGCN variant using weight parameters outperforms the state-of-the-art methods, while the CGCN variant without using weight parameters outperforms the benchmarks only in the withinversion defect prediction. • Different from “ GCN2defect: Graph Convolutional Networks for SMOTETomekbased Software Defect Prediction ” on 2021 IEEE 32nd International Symposium on Software Reliability Engineering (ISSRE), in addition to the features of software network, this paper also combines the semantic features of source codes, and extends to cross-version and cross-project predictions. Experimental results show that the proposed method in this paper has better robustness.