A multi-target software defect prediction method based on multi-task multi-view learning

By combining multi-task, multi-perspective learning and static analysis, a multi-task, multi-perspective neural network model is constructed, which solves the problems of high complexity and false positives and false negatives in single-target prediction in existing technologies. It achieves simultaneous and efficient prediction of defect tendency, location and type, thereby improving software quality and reliability.

CN115221045BActive Publication Date: 2026-05-29BEIHANG UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIHANG UNIV
Filing Date
2022-06-27
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Most existing software defect prediction methods can only achieve a single objective, resulting in high operational complexity and high resource consumption. Furthermore, static analysis tools suffer from false positives and false negatives.

Method used

By employing a multi-task, multi-perspective learning approach and combining static analysis, we extract the metric, spatial structure, and semantic features of the code, and construct a multi-task, multi-perspective neural network model to simultaneously predict defect tendency, location, and type.

Benefits of technology

It improves the efficiency and accuracy of defect prediction, significantly reduces false positives and false negatives in static analysis tools, provides more comprehensive and accurate defect information, and helps developers efficiently discover defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115221045B_ABST
    Figure CN115221045B_ABST
Patent Text Reader

Abstract

The application provides a multi-target software defect prediction method based on multi-task multi-view learning, which can predict defects in the to-be-tested code with unknown defects based on the historical code with known defects of the target software; solves the problem that the traditional software defect prediction method can only complete one defect prediction target and uses different prediction methods for different defect prediction targets, and the complexity and resource consumption are large, and can effectively improve the false alarm and missed alarm conditions of the static analysis tool. Based on the integrated static analysis method, multi-view feature information including code metric features, defect space structure features and defect typical semantic features can be extracted. Through the constructed multi-task multi-view neural network model, the defect tendency, position and type of the target code are predicted, accurate and efficient defect prediction information in multiple aspects is provided, the false alarm and missed alarm conditions of the static analysis are greatly improved, and the developer can complete effective defect mining.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention provides a multi-objective software defect prediction method based on multi-task and multi-perspective learning, belonging to the field of software defect prediction. Background Technology

[0002] Accurate and effective software defect prediction is crucial for software reliability assurance and maintenance. However, the increasing richness of software functions and the growing complexity of software structures place higher demands on software defect prediction methods. Therefore, software defect prediction has been an active area of ​​research in software engineering for many years. The core of software defect prediction work mainly includes the following three prediction objectives:

[0003] (1) Predicting the defect tendency of the code: Predicting whether the code to be tested in the target software contains defects;

[0004] (2) Predict the location of defects in the code: Predict the location of defects in the software code;

[0005] (3) Predict the type of defects in the code: Predict the type of defects in the software code.

[0006] However, most common defect prediction methods can only achieve one of the above objectives, i.e., single-objective defect prediction methods. They can only provide defect prediction information for one aspect, thus offering relatively limited assistance to developers in defect discovery. Furthermore, using different defect prediction methods for different defect prediction objectives significantly increases the operational complexity and time consumption of defect prediction work, resulting in poor usability. Therefore, developing a multi-objective software defect prediction method that can accurately complete multiple defect prediction objectives simultaneously can greatly improve the efficiency of defect prediction, which is highly significant. Meanwhile, multi-task multi-view learning is a novel machine learning method that can fully utilize information from different perspectives to effectively learn multiple related tasks. Its excellent performance in computer vision and natural language processing demonstrates that adopting a multi-task multi-view neural network model can effectively improve model performance. Moreover, static analysis methods, which extract defect warnings by directly scanning target code, can provide sufficient defect information from multiple perspectives, such as defect location information and defect type information. Therefore, this invention chooses to construct a multi-objective software defect prediction method through multi-task multi-view learning and static analysis methods.

[0007] This invention provides a multi-task, multi-perspective learning-based method for predicting software defects. It can predict defects in code under test with unknown defects based on historical code showing known defects in the target software. It extracts the spatial distribution and semantic features of defects from the source code using an ensemble static analysis method, deeply mining defect information from multiple perspectives. The constructed multi-task, multi-perspective neural network model possesses powerful learning capabilities, fully considering the correlation between features from each task and perspective, thus simultaneously predicting the tendency, location, and type of defects in the code under test. It fully considers the correlation between multiple software defect prediction tasks and features, sharing the learning experience from each task, thereby effectively improving the efficiency and accuracy of software defect prediction and significantly reducing false positives and false negatives of static analysis tools. This invention can provide software developers with more comprehensive and accurate defect prediction information from multiple perspectives, thereby efficiently completing defect mining and effectively improving software quality and reliability. Summary of the Invention

[0008] (I) Purpose

[0009] This invention presents a multi-objective software defect prediction method based on multi-task, multi-perspective learning. It can predict defects in code under unknown defect conditions based on historical code with known defects in the target software, belonging to the field of software defect prediction. This method addresses the problem of high complexity and resource consumption in traditional software defect prediction methods that can only achieve one defect prediction objective and employ different prediction methods for different defect prediction objectives. Furthermore, it effectively improves the false positives and false negatives of static analysis tools. This invention can extract multi-perspective feature information, including code metric features, defect spatial structure features, and typical semantic features of defects, based on integrated static analysis methods. Through the multi-task, multi-perspective neural network model constructed in this invention, it can simultaneously predict the defect tendency, location, and type of the target code based on the extracted multi-perspective feature information, providing accurate and efficient defect prediction information from multiple aspects, significantly improving the false positives and false negatives of static analysis, and helping developers to effectively discover defects.

[0010] (II) Technical Solution

[0011] This invention discloses a multi-target software defect prediction method based on multi-task, multi-perspective learning. It can predict defects in the code to be tested under unknown defect conditions based on the historical code of the target software with known defect conditions. The specific implementation steps are as follows: Figure 1 As shown;

[0012] Step 1: Collect defect data of the target software's historical code, including whether the code has defects, the number of lines of code with defects, and the type of defects, so as to provide labels for defect tendency, defect location, and defect type prediction for subsequent defect prediction model training;

[0013] Step 2: Extract defect information from the historical code of the target software using integrated static analysis methods, including code measurement information, whether there are defect alarms after the code is scanned, the location information of the code where the defect alarm is located, and the specific description information of the defect alarm.

[0014] Step 3: Extract software code metrics from the defect information obtained from integrated static analysis, including the number of lines of code, cyclomatic complexity, number of branch statements, etc., to form a code metric feature vector;

[0015] Step 4: Extract the location information of software code defect alarms from the defect information obtained from integrated static analysis, divide the source code into 20 code segments, and use multi-hot encoding to mark the corresponding defect locations to form a defect spatial structure feature vector;

[0016] Step 5: Extract the descriptive information of software code defect alarms from the defect information obtained from integrated static analysis, calculate the semantic similarity between the defect description and the description of each defect category, and use multi-hot encoding to mark the corresponding defect categories to form a typical semantic feature vector of defects;

[0017] Step 6: Combine the code metric feature vector, defect space structure feature vector, and defect typical semantic feature vector obtained in steps 3-5 into a multi-view feature vector;

[0018] Step 7: Input the multi-view feature vectors of the target software's historical code and the corresponding label data into the constructed multi-task multi-view neural network model to complete the training and optimization;

[0019] Step 8: Execute steps 2-6 sequentially on the code to be tested in the target software to obtain the multi-view feature vector of the code to be tested;

[0020] Step 9: Input the multi-view feature vector of the target software code to be tested into the multi-task multi-view neural network model trained in Step 7 to obtain the defect tendency, location and type prediction results of the code to be tested.

[0021] Through the above steps, based on historical code showing known defects in the target software, the presence, location, and type of defects in the code under test with unknown defects can be predicted simultaneously. This solves the problem of traditional software defect prediction methods, which can only achieve one defect prediction objective and require different prediction methods for different defect prediction objectives, resulting in high complexity and resource consumption. Furthermore, it effectively improves the false positives and false negatives of static analysis tools. This invention can simultaneously predict the defect tendency, location, and type of target code based on integrated static analysis and a multi-task, multi-perspective model, providing accurate and efficient defect prediction information from multiple aspects to help developers effectively discover defects. A schematic diagram of the principle of this invention is shown below. Figure 2 As shown. This invention is based on the use of multiple static analysis methods s1 to s2. n Source code f to f with analysis software n The obtained static analysis results are then integrated to extract code metric information, including whether the code exhibits defect alarms after scanning, the location of the alarms, and the specific description of the alarms. Multi-perspective features, including code metric features, defect spatial structure features, and typical defect semantic features, are then extracted from the integrated static analysis results to generate multi-perspective feature vectors. These multi-perspective feature vectors are input into a trained and optimized multi-task multi-perspective neural network model, enabling simultaneous prediction of code defect tendency, defect location, and defect type, resulting in corresponding multi-objective defect prediction results. Thus, this invention can achieve accurate and efficient multi-objective software defect prediction and effectively improve the false negatives and false positives of static analysis tools.

[0022] Step 1, "collecting defect data from the target software's historical code, including whether the code has defects, the number of lines of code with defects, and the type of defects, thereby providing labels for defect tendency, defect location, and defect type predictions for subsequent defect prediction model training," is implemented as follows: Defect information from the target software's historical code is collected from a software defect library or defect dataset. The target software code can be written in common languages ​​such as C / C++ or Java. An automated extraction tool is developed to extract whether defects exist, their locations, and their detailed descriptions. Then, corresponding labels for defect tendency, defect location, and defect type predictions are generated through hot encoding and stored uniformly in a CSV file.

[0023] Step 2, which involves "extracting defect information from the target software's historical code using integrated static analysis methods, including code measurement information, whether the code contains defects, the location of the defects, and specific defect descriptions," is implemented as follows: Multiple static analysis tools in the corresponding language are used to scan and analyze the defects in the target software's historical code. The different static analysis results generated by these tools are then extracted and integrated. Specifically, code measurement results are extracted using code measurement software, while defect analysis results, including defect location information and specific descriptions, are extracted using open-source static analysis tools. The extracted defect information is then stored uniformly in a CSV file.

[0024] Step 3, which involves "extracting software code metrics from the defect information obtained through integrated static analysis, including the number of lines of code, cyclomatic complexity, and the number of branch statements, to form a code metric feature vector," is specifically implemented as follows: Eleven code metric indicators are selected from the defect information extracted in Step 2, including the number of lines of code, the number of lines of code excluding blank lines, the number of statements, the percentage of branch statements, the percentage of comments, the number of methods, the number of lines containing the most complex method, the number of lines containing the deepest nested block, the maximum nesting depth, the average nesting depth, and cyclomatic complexity. These indicators are combined into a one-dimensional vector, which is the code metric feature vector. This vector is part of the input features required for training the prediction model in subsequent steps. If F1 to F2 are used... 11 Let each of the 11 code metrics represent a different feature vector, then the code metric feature vector can be represented as follows:

[0025] Feature1=[F1, F2, F3,...,F 11 ].

[0026] Step 4, which involves "extracting the location information of software code defect alarms from the defect information obtained from integrated static analysis, dividing the source code into 20 code segments, and using multi-hot encoding to mark the corresponding defect locations to form a defect spatial structure feature vector," is specifically implemented as follows: From the defect information extracted in Step 2, the line number of the defect is selected. The code is then divided into 20 segments, and multi-hot encoding is used to mark the segments containing the defect alarm lines, generating a location marker vector. Furthermore, during marking, alarms are categorized into "Error" and "Warning" based on their severity for each tool's results. Combining the defect location marker vectors from each tool's alarms yields the defect spatial structure feature vector. This vector is also part of the input features required for training the prediction model in subsequent steps. If... and Let represent the number of Error alerts and Warning alerts in the 20 code segments, respectively. Then, the defect space structure feature vector can be represented as:

[0027] in This represents the concatenation of vectors.

[0028] Step 5, which involves "extracting descriptive information of software code defect alarms from the defect information obtained from integrated static analysis, calculating the semantic similarity between the defect description and the description of each defect category, and using multi-hot encoding to label the corresponding defect categories to form a typical semantic feature vector of defects," is specifically implemented as follows: The detailed descriptions of defect alarms are selected from the defect information extracted in Step 2, and the semantic similarity between the description of the defect alarm and the description of the defect type is calculated. This allows for labeling of defect types using a hot encoding method. Specifically, we employ the Seven Pernicious Kingdoms defect classification method based on Common WeaknessEnumeration, which categorizes defects into the following types: as shown in Table 1.

[0029] Table 1

[0030]

[0031] Then, during labeling, the similarity between the defect description and the defect category name, and the similarity between the defect description and the defect category content are calculated separately. This comprehensively examines the typical types of the defect description and forms a typical semantic feature vector of the defect. This is the final part of the input features required for subsequent steps in training the prediction model. If using... and Let the similarity between the description of the defect alarm and the names and descriptions of the eight defect types be represented respectively. Then, the typical semantic feature vector of the defect can be expressed as:

[0032] in This represents the concatenation of vectors.

[0033] Step 6, which involves "combining the code metric feature vector, defect space structure feature vector, and typical defect semantic feature vector obtained in steps 3-5 into a multi-perspective feature vector," is specifically implemented as follows: After steps 2-5, the metric feature vector, defect space structure feature vector, and typical defect semantic feature vector of the target software's historical code have been obtained. These three vectors are then sequentially concatenated to obtain the multi-perspective feature vector, namely:

[0034]

[0035] Step 7, "training and optimizing a multi-task, multi-view neural network model constructed by inputting the multi-view feature vectors of the target software's historical code with the corresponding label data," is specifically implemented as follows: The multi-view feature vectors of the target software's historical code are used as input features to the constructed multi-task, multi-view neural network model, with the corresponding label data as the standard output. After configuring the training parameters, the multi-task, multi-view neural network model is trained and automatically optimized. The structure of the constructed neural network model is as follows: Figure 3 As shown, it mainly consists of three feature encoders and three task decoders. Each feature encoder comprises a Convolutional Neural Network (CGRU) layer, a Gated Recurrent Unit (GRU) layer, and two fully connected layers, and each encoder corresponds to input features from one viewpoint. Each decoder consists of a GRU layer and two fully connected layers, and each decoder corresponds to a prediction task. After the encoders encode the multi-view feature vectors, they are combined through a vector concatenation layer and then fed into a spatial attention layer for training. This process acquires the spatial importance of different features and performs multi-view feature fusion, enabling the decoders to effectively decode based on the spatial importance of different features. Ultimately, after training, the three decoders can respectively perform defect tendency prediction, defect location prediction, and defect type prediction tasks. In other words, the model, optimized based on the target software's historical code, can be used to perform defect prediction for the target software's code under test.

[0036] Specifically, step 8 involves "executing steps 2-6 sequentially on the code to be tested in the target software to obtain the multi-view feature vector of the code to be tested." The specific procedure is as follows: When predicting the code to be tested in the target software, steps 2 to 6 need to be repeated to obtain the code metric feature vector, defect spatial structure feature vector, and typical semantic feature vector of the code to be tested in the target software, respectively, and these are combined into a multi-view feature vector.

[0037] Step 9, which involves "inputting the multi-view feature vectors of the target software code under test into the multi-task multi-view neural network model trained in step 7 to obtain the defect tendency, location, and type prediction results of the code under test," is specifically implemented as follows: The multi-view feature data of the target software code under test from step 8 is input into the multi-task multi-view neural network model trained in step 7 to obtain the defect tendency, location, and type prediction results of the code under test. Compared with the original static analysis results, the optimized model significantly improves the false negatives and false positives, enabling accurate and efficient prediction of defect tendency, location, and type.

[0038] (III) Advantages and Efficacy

[0039] This invention discloses a multi-objective software defect prediction method based on multi-task, multi-perspective learning, belonging to the field of software defect prediction. This method addresses the problem of traditional software defect prediction methods, which can only achieve one defect prediction objective and suffer from high complexity and resource consumption when different prediction methods are used for different defect prediction objectives. Furthermore, it effectively improves the false positives and false negatives of static analysis tools. This invention can extract multi-perspective feature information, including code metric features, defect spatial structure features, and typical semantic features of defects, based on integrated static analysis methods. Through the multi-task, multi-perspective neural network model constructed by this invention, the defect tendency, location, and type of the target code can be predicted simultaneously based on the extracted multi-perspective feature information, providing accurate and efficient defect prediction information from multiple aspects, significantly improving the false positives and false negatives of static analysis, and helping developers to effectively discover defects. Attached Figure Description

[0040] Figure 1 This is a flowchart of the method provided in an embodiment of the present invention.

[0041] Figure 2 This is a schematic diagram illustrating the principle of a multi-objective software defect prediction method based on multi-task and multi-perspective learning, provided in an embodiment of the present invention.

[0042] Figure 3 It is a neural network model structure.

[0043] Figure 4a These are the curves showing the changes in the loss function values ​​for the three prediction tasks during the training process; the solid line represents the training set results, while the dashed line represents the validation set results.

[0044] Figure 4b These are the prediction accuracy curves for the three prediction tasks during the training process; the solid line represents the training set results, while the dashed line represents the validation set results. Detailed Implementation

[0045] To illustrate the specific implementation methods in this invention more concretely, the following will use a code dataset from the open-source project JulietTestSuite 1.3 as an example to describe the detailed implementation methods of this invention. It contains over 64,000 test cases written in C and C++ and corresponding defect information, which can be used to apply and verify the methods in this invention.

[0046] (1): Collect defect data from the target dataset, including whether the code has defects, the number of lines of code with defects, and the type of defects, as labels for the corresponding defect prediction task. Then, the target dataset is divided into historical code and code to be tested, with historical code accounting for 80% and code to be tested accounting for 20%. In the subsequent defect prediction process, the defect prediction model in this invention can predict the defect tendency, defect location, and defect type of the code to be tested in the target dataset after training and optimization based on the historical code of the target dataset;

[0047] (2): Defect information from the historical code of the target software was extracted using integrated static analysis methods. This included code metrics, whether there were defect alerts after the code was scanned, the location of the defect alerts in the code, and the specific description of the defect alerts. The data was then saved as a CSV file. We selected three common open-source static analysis tools for C / C++: Cppcheck, Flawfinder, and Tscancode.

[0048] (3): Extract 11 metrics from the defect information obtained from integrated static analysis, including the number of lines of code, the number of lines of code after removing blank lines, the number of statements, the percentage of branch statements, the percentage of comments, the number of methods, the number of lines where the most complex method is located, the number of lines where the deepest nested block is located, the maximum nesting depth, the average nesting depth and cyclomatic complexity, i.e. Feature1.

[0049] (4): Extract the location information of software code defect alarms from the defect information obtained from integrated static analysis, divide the source code into 20 code segments, and use multi-hot encoding to mark the corresponding defect locations to form a defect space structure feature vector, namely Feature2.

[0050] (5): Extract the description information of software code defect alarms from the defect information obtained from integrated static analysis, calculate the semantic similarity between the defect description and the description of each defect category, and use multi-hot encoding to mark the corresponding defect category to form a typical semantic feature vector of defects, namely Feature3.

[0051] (6): Combine the code metric feature vector, defect spatial structure feature vector, and defect typical semantic feature vector obtained in steps 3-5 into a multi-view feature vector, i.e., Feature. The first 11 columns of the multi-view feature vector obtained from some files are shown in Table 2:

[0052] Table 2

[0053] name lines true_lines Statement sPercent Br PercentLin Functions LineNumb LineNumb Maximum BAverageBloc Average C CWE134_Uncontrolled_Format_Str i148 99 57 10.5 23 5 32 50 5 1.56 2.2 CWE127_Buffer_Underread__mallo 154 101 69 10.1 31.8 5 57 31 4 1.7 2.4 CWE190_Integer_Overflow__int_m 189 132 75 21.3 24.3 7 48 36 3 1.45 3.29 CWE124_Buffer_Underwrite__new_ 157 102 60 6.7 29.3 5 59 33 3 1.57 1.8 CWE134_Uncontrolled_Format_Str i89 54 30 0 25.8 6 35 38 2 0.9 1 CWE23_Relative_Path_Traversal__w 196 144 75 12 16.8 4 66 86 4 1.61 3.5 CWE190_Integer_Overflow__int64_ 178 123 76 11.8 24.2 10 59 32 3 1.18 1.9 CWE124_Buffer_Underwrite__new_ 55 32 18 5.6 40 0 35 45 3 1.44 1.5 CWE122_Heap_Based_Buffer_Over 173 122 84 11.9 27.7 8 37 51 3 1.25 2.25 CWE190_Integer_Overflow__int64_ 105 61 44 0 29.5 5 30 22 1 0.7 1 CWE195_Signed_to_Unsigned_Con 83 42 29 0 37.3 4 24 26 1 0.66 1 CWE121_Stack_Based_Buffer_Over 116 74 48 0 30.2 4 28 46 3 1.23 1 CWE122_Heap_Based_Buffer_Over 102 56 36 0 28.4 4 30 32 1 0.69 1 CWE23_Relative_Path_Traversal__c 123 74 39 10.3 26 4 37 56 5 1.26 2.25

[0054] (7): Input the multi-view feature vector of the target software history code and the corresponding label data obtained in the first step into the multi-task multi-view neural network model as described above to complete the training and optimization. We trained for 100 cycles and selected 10% of the samples in the training set as the validation set to verify whether underfitting or overfitting occurred during the training process. The following training process record can be obtained.

[0055] Depend on Figure 4a and Figure 4b It can be seen that the training accuracy continuously improves and the loss function value continuously decreases and tends to stabilize during the training process. At the same time, no overfitting or underfitting is shown in the validation set, and it can still maintain high accuracy. Therefore, the training and optimization process is successful, and the next step is to predict the defects of the code to be tested.

[0056] (8): Execute steps 2-6 sequentially on the code to be tested of the target software to obtain the multi-view feature vector of the code to be tested;

[0057] (9): Input the multi-view feature vector of the target software code to be tested into the multi-task multi-view neural network model trained in step 7 to obtain the defect tendency, location and type prediction results of the code to be tested. The specific contents are as follows:

[0058] 1) The results of defect tendency prediction are shown in Table 3;

[0059] Table 3

[0060]

[0061]

[0062] In this framework, Acc represents Accuracy, Rec represents Recall, Pre represents Precision, and F represents the F1-measure evaluation metric. Higher values ​​of these metrics are generally better, and both Rec and Pre reflect the false positives and false negatives of each prediction method. The subscript avg represents the average value calculated from all code files. Therefore, we can see that the method in this invention significantly improves accuracy, recall, and precision compared to the three static analysis tools when performing defect propensity prediction, while effectively reducing false positives and false negatives, thus achieving effective defect propensity prediction.

[0063] 2) The results of defect location prediction are shown in Table 4;

[0064] Table 4

[0065] Metric Cppcheck Tscancode FlawFinder Proposed <![CDATA[Sub acc ]]> 0.9682 0.9680 0.9535 0.9928 <![CDATA[Sub pre ]]> 0.4867 0.2644 0.1081 0.9018 <![CDATA[Sub rec ]]> 0.0114 0.0041 0.0653 0.8723

[0066] In this diagram, Sub represents the model output, while acc represents accuracy, rec represents recall, and pre represents precision. Higher values ​​for each are better, and both Rec and Pre reflect the false positives and false negatives of each prediction method. Therefore, we can see that the method in this invention significantly improves accuracy, recall, and precision compared to the three static analysis tools when predicting defect locations, while effectively reducing false positives and false negatives, thus achieving effective defect location prediction.

[0067] 3) The results of defect type prediction are shown in Table 5;

[0068] Table 5

[0069] Metric Cppcheck Tscancode FlawFinder Proposed <![CDATA[Sub acc ]]> 0.8659 0.8603 0.8437 0.9879 <![CDATA[Sub pre ]]> 0.4046 0.2177 0.2798 0.9545 <![CDATA[Sub rec ]]> 0.0051 0.0192 0.1019 0.9485

[0070] In this diagram, Sub represents the model output, while acc represents accuracy, rec represents recall, and pre represents precision. Higher values ​​for each are better, and both Rec and Pre reflect the false positives and false negatives of each prediction method. Therefore, we can see that the method in this invention significantly improves accuracy, recall, and precision compared to the three static analysis tools when predicting defect types, while effectively reducing false positives and false negatives, thus achieving effective defect type prediction.

[0071] 4) Summary of Results:

[0072] Based on the above results, we can verify that the method in this invention can simultaneously and accurately predict the defect tendency, defect location, and defect type in the code under test, thereby effectively improving the efficiency and accuracy of software defect prediction. Furthermore, compared with the three static analysis tools, the method in this invention significantly reduces false positives and false negatives. Therefore, this invention can provide software developers with more comprehensive and accurate defect prediction information from multiple perspectives, thereby efficiently completing defect discovery and effectively improving software quality and reliability.

Claims

1. A multi-objective software defect prediction method based on multi-task, multi-view learning, characterized in that: Step 1: Collect defect data of the target software's historical code, including whether the code has defects, the number of lines of code with defects, and the type of defects, to provide labels for defect tendency, defect location, and defect type prediction for subsequent defect prediction model training; Step 2: Extract defect information from the historical code of the target software using integrated static analysis methods, including code measurement information, whether there are defect alarms after the code is scanned, the location information of the code where the defect alarm is located, and the specific description information of the defect alarm. Step 3: Extract software code metrics from the defect information obtained from integrated static analysis, including the number of lines of code, cyclomatic complexity, and number of branch statements, to form a code metric feature vector; Step 4: Extract the location information of software code defect alarms from the defect information obtained from integrated static analysis, divide the source code into 20 code segments, and use multi-hot encoding to mark the corresponding defect locations to form a defect spatial structure feature vector; Specifically, the code lines containing defects are selected from the defect information extracted in step 2. The code is then divided into 20 segments on average. The segments containing the defect alarm lines are marked using a hot coding method to generate location marker vectors. During the marking process, alarms for each tool are classified into two categories, Error and Warning, based on their severity. The defect location marker vectors for each tool are combined to obtain a defect spatial structure feature vector, which is also part of the input features required for training the prediction model in subsequent steps. use and Let represent the number of Error alerts and Warning alerts in the 20 code segments, respectively. Then, the defect space structure feature vector is represented as: ,in This represents the concatenation of vectors; Step 5: Extract the descriptive information of software code defect alarms from the defect information obtained from integrated static analysis, calculate the semantic similarity between the defect description and the description of each defect category, and use multi-hot encoding to mark the corresponding defect categories to form a typical semantic feature vector of defects; Step 6: Combine the code metric feature vector, defect space structure feature vector, and defect typical semantic feature vector obtained in steps 3-5 into a multi-view feature vector; Step 7: Input the multi-view feature vectors of the target software's historical code and the corresponding label data into the constructed multi-task multi-view neural network model to complete the training and optimization; Step 8: Execute steps 2-6 sequentially on the code to be tested in the target software to obtain the multi-view feature vector of the code to be tested; Step 9: Input the multi-view feature vector of the target software code to be tested into the multi-task multi-view neural network model trained in Step 7 to obtain the defect tendency, location and type prediction results of the code to be tested.

2. The multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 1, characterized in that: In step 1, the specific steps are as follows: collect defect information of the target software's historical code from a software defect library or defect dataset. The target software code is written in common C / C++ or Java languages. Develop an automated extraction tool to extract whether a defect exists, the location of the defect, and the specific description of the defect. Then, generate corresponding labels for defect tendency, defect location, and defect type prediction through hot encoding, and store them uniformly using a CSV file.

3. The multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 1, characterized in that: In step 2, specifically: the defects in the historical code of the target software are scanned and analyzed by calling multiple static analysis tools of the corresponding language, and the different static analysis results generated by the multiple static analysis tools are extracted and integrated; among them, the code measurement results are extracted by code measurement software, while the defect analysis results are extracted by open-source static analysis tools, including defect location information and specific description information; the extracted defect information is uniformly stored in a CSV file.

4. A multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 1, 2, or 3, characterized in that: In step 3, specifically: 11 code metrics are selected from the defect information extracted in step 2, including line count, line count excluding blank lines, statement count, percentage of branch statements, percentage of comments, number of methods, line count of the most complex method, line count of the deepest nested block, maximum nesting depth, average nesting depth, and cyclomatic complexity. These metrics are combined into a one-dimensional vector, which is the code metric feature vector; it is part of the input features required for training the prediction model in subsequent steps; and F1 to F2 are used. 11 Let each of the 11 code metrics represent a different feature vector. .

5. A multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 1, 2, or 3, characterized in that: In step 5, specifically: Detailed descriptions of defect alarms are selected from the defect information extracted in step 2. The semantic similarity between the description of the defect alarm and the description of the defect type is calculated, and the defect type is labeled using a hot coding method. Specifically, the SevenPernicious Kingdoms defect classification method based on Common Weakness Enumeration is adopted, which categorizes defects into eight types: runtime environment, alarm handling, improper API handling, improper input validation, poor code quality, insufficient encapsulation, security feature related, and time and state related. Then, during labeling, the similarity between the defect description and the defect category name, and the similarity between the defect description and the defect category content are calculated separately to comprehensively examine the typical types of the defect description and form a typical semantic feature vector of the defect. This is the final part of the input features required for training the prediction model in subsequent steps. and Let the similarity between the description of the defect alarm and the names and descriptions of the eight defect types be represented respectively. Then, the typical semantic feature vector of the defect is represented as follows: ,in This represents the concatenation of vectors.

6. The multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 5, characterized in that: In step 6, specifically: after steps 2-5, the metric feature vector, defect spatial structure feature vector, and typical semantic feature vector of the target software's historical code have been obtained; then, these three vectors are sequentially concatenated to obtain the multi-view feature vector, namely: 。 7. The multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 6, characterized in that: In step 7, specifically: the multi-view feature vectors of the target software's historical code are used as input features to construct a multi-task, multi-view neural network model, with the corresponding label data as the standard output. After configuring the training parameters, the multi-task, multi-view neural network model is trained and automatically optimized. The constructed neural network model structure includes three feature encoders and three task decoders; each feature encoder consists of a convolutional neural network layer. The encoder consists of a NetworksLayer, a GatedRecurrentUnitsLayer, and two fully connected layers, denoted as CGRU. Each encoder corresponds to input features from one viewpoint. Each decoder consists of a GatedRecurrentUnitsLayer and two fully connected layers, denoted as GRU, and each decoder corresponds to a prediction task. After the encoder encodes the multi-view feature vectors, they are combined through a vector concatenation layer and fed into a spatial attention layer for training. This process acquires the spatial importance of different features and performs multi-view feature fusion, enabling the decoder to effectively decode based on the spatial importance of different features. Finally, after training, the three decoders can respectively perform defect tendency prediction, defect location prediction, and defect type prediction tasks. In other words, the model, optimized based on the target software's historical code, is used to perform subsequent defect prediction for the code to be tested in the target software.

8. The multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 1, characterized in that: In step 8, specifically, when predicting the code to be tested of the target software, steps 2 to 6 need to be repeated to obtain the code metric feature vector, defect spatial structure feature vector, and defect typical semantic feature vector of the code to be tested of the target software, and combine them into a multi-view feature vector.

9. The multi-objective software defect prediction method based on multi-task, multi-view learning according to claim 1, characterized in that: In step 9, specifically: the multi-view feature data of the target software code to be tested in step 8 is input into the multi-task multi-view neural network model trained in step 7 to obtain the defect tendency, location and type prediction results of the code to be tested; compared with the original static analysis results, the optimized model results improve the false negative and false positive situation, and achieve the goal of predicting the defect tendency, location and type.