A method for automatically locating root cause of defects
By constructing a heterogeneous graph and utilizing deep learning methods, the root cause of defects is automatically located, overcoming the limitations and inefficiencies of existing tools in defect location and achieving efficient and accurate identification of the root cause of defects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2023-09-07
- Publication Date
- 2026-05-29
AI Technical Summary
Existing tools have limitations in locating the root cause of defects. They cannot accurately identify the specific lines of change that caused the defect, and they take a long time, which affects the efficiency of developers' analysis.
By employing a heterogeneous graph attention neural network and a ranking neural network, node embedding vectors are extracted from code change information by constructing a heterogeneous graph, and deep learning methods are used to rank the nodes to automatically locate the root cause of the defect.
It improves the accuracy and efficiency of locating the root cause of defects, reduces developers' time and costs, and improves software quality and tool precision.
Smart Images

Figure CN117234908B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of program analysis and defect localization, and in particular to a method for automatically locating the root cause of a defect. Background Technology
[0002] Modern software development heavily relies on version control systems to manage source code and track changes. Version control systems use commits as the basic unit, with each commit representing a snapshot of the entire project. Among all types of commits, there are bug fix commits, which contain a wealth of information about the bug and are therefore often used by developers to analyze its root cause. Furthermore, many tools automatically identify bug fix commits to find those that introduced the bug. Unfortunately, however, many bug fix commits contain numerous code changes unrelated to the bug's cause. This irrelevant code can hinder bug analysis and reduce the accuracy of tools that identify bug-inducing commits.
[0003] To illustrate the impact of irrelevant code changes in commits that fix defects, let's take the popular open-source project Hadoop as an example. Hadoop has a commit, a2a5cb60b09, that fixes a defect. This commit modified four files, including 37 added lines and 17 deleted lines. According to the commit information, the root cause of the defect lies in a single line of code on line 97 of the `FairCallQueue.java` file. This line causes the first child queue to have extra space. Directly running automated tools to retrieve the corresponding commit that introduced the defect would introduce a lot of noise, leading to inaccurate results. Furthermore, this noise would also affect developers' analysis of the defect's cause, reducing developer efficiency. Currently, most tools for removing noise from commits use static analysis methods, such as using refactoring detection tools like RefDiff to remove code changes related to refactoring within commits. However, these tools have three drawbacks: first, their detection range is limited, unable to detect all types of refactoring operations, only 13 types, while there are a total of 65 types of refactoring operations; second, their accuracy is low, unable to accurately locate specific lines of change, especially those within method bodies; and third, using these tools is often time-consuming. Researchers have integrated refactoring detection tools like RefDiff into tools for automatically finding defect-inducing code, but this has not yielded satisfactory results. To address the limitations of these static methods, this paper considers both the semantics of the changed code in the commit and the relationships between the changed code, further removing noise from the commit, and sorting all lines of change according to their probability of being the root cause of the defect, thereby locating the root cause of the defect. Summary of the Invention
[0004] The purpose of this invention is to address the shortcomings of existing technologies by proposing a method for automatically locating the root cause of defects.
[0005] The objective of this invention is achieved through the following technical solution: a method for automatically locating the root cause of a defect, comprising the following steps:
[0006] S1. Obtain code change information c from the commit, where c includes the source code src_code before the change, the source code dst_code after the change, and the modified lines t, including deleted lines. and add lines ;
[0007] S2. Process the code change information c in the submission, and extract the relationships between all modified lines from t, src_code, and dst_code to construct a heterogeneous graph G;
[0008] S3. Input the heterogeneous graph G into the heterogeneous graph attention neural network. For each node in the heterogeneous graph G... Obtain the embedding vector representation corresponding to this node. ;
[0009] S4. Represent the node's embedding vector. Input into a sorting neural network to obtain the score of the current node. ;
[0010] S5. Sort the scores corresponding to all nodes, and the node with the highest score is the node that is the root cause of the current defect.
[0011] Further, step S2 includes the following sub-steps:
[0012] S21. Use the javaParser tool to construct abstract syntax trees for src_code and dst_code respectively. The abstract syntax tree corresponding to src_code is: The abstract syntax tree corresponding to dst_code is ;Delete the lines in all modified lines t Mapped to From the nodes, obtain the deleted node. ;Add lines to all modified lines t Mapped to From the nodes, we get the added nodes. ;
[0013] S22. In the source code src_code before the change and the source code dst_code after the change, based on the deleted nodes... and adding nodes The relationships between them are used to construct corresponding types of graphs, including control flow graphs, data dependency graphs, function call graphs, and class member reference graphs;
[0014] S23. For each type of graph in the source code src_code before the change and the source code dst_code after the change, use a depth-first search method to extract whether there is a path between the nodes. If a path exists, add an edge of the corresponding type between the corresponding nodes to obtain the graph before the change. And the revised diagram Otherwise, proceed directly to step S24;
[0015] S24, Judgment Diagram Can the deleted row in the middle node be mapped to the graph? Add a row to the corresponding node, if The deleted row in the middle node can be mapped to If a row is added to the corresponding node, an edge is added between the two nodes to construct a heterogeneous graph G; otherwise, there is no connecting edge between the two nodes.
[0016] Furthermore, the heterogeneous graph attention neural network includes an embedding layer, a node attention layer, and a semantic attention layer. The embedding layer is a codeBERT encoder pre-trained based on Transformer, which converts the code contained in the graph nodes into their corresponding embedding vector representations. Then, a node attention layer aggregates the embedding of each node with the embeddings of its neighboring nodes; next, a semantic attention layer aggregates the embeddings of the same nodes corresponding to all types of graphs through an attention mechanism to obtain the final node embedding vector representation. .
[0017] Further, step S3 includes the following sub-steps:
[0018] S31. Using a Transformer-based pre-trained codeBERT encoder to process nodes in a heterogeneous graph G. The corresponding code is encoded and converted into a numerical representation. Then, this encoder converts the numerical representation into a multidimensional vector representation. ;
[0019] S32. Map the features of different types of nodes to the same feature space, as shown below:
[0020]
[0021] in, It is the feature vector output by the codeBERT encoder. It is the matrix to be learned. The nodes are obtained through a unified mapping. eigenvectors;
[0022] S33. The heterogeneous graph attention neural network calculates the attention score at the node level, and its expression is:
[0023]
[0024] in, It is a normalized node-level attention score, representing the node's... For nodes The degree of importance; Representative node Based on metapath All adjacent nodes, represents the Sigmoid activation function, and || represents the concatenation operator; These are parameters that need to be optimized during training;
[0025] For each type of metapath compute nodes corresponding feature vector As shown below:
[0026] =
[0027] in, It is the normalized attention score;
[0028] Subsequently, the heterogeneous graph attention neural network computes the importance of each type of metapath, given a set of metapaths. The formula for calculating the importance of each type of metapath is:
[0029]
[0030] in, yes Attention score for this type of meta-path Represents the nodes in the graph. , and These are all parameters to be learned. It is an activation function;
[0031] Normalize the weights of all metapaths to obtain the final normalized weights:
[0032]
[0033] in, Represents the final normalized weights;
[0034] All feature vectors under different types of metapaths By combining these elements, we obtain the final feature embedding vector representation. Its expression is:
[0035] .
[0036] Further, step S4 includes the following sub-steps:
[0037] S41. Combine all nodes in the heterogeneous graph G into pairs to obtain node pairs. >;
[0038] S42, For each pair of nodes >, compute nodes In the final arrangement, it has higher priority than True probability As shown in the formula below:
[0039]
[0040] S43, For each pair of nodes >, sorting neural networks will all be based on their feature vectors and Assign it a fraction and and calculate the nodes In the final arrangement, it has higher priority than The probability is shown in the following formula:
[0041]
[0042] S44, Ranking Neural Networks Based on True Probability and the calculated probability To update the parameters of the sorting neural network, the loss function of the sorting neural network is as follows:
[0043]
[0044] in, This is the loss function for the sorting neural network.
[0045] The beneficial effects of this invention are as follows: It overcomes the limitations of traditional static analysis techniques by employing deep learning methods to consider both the semantics of code changes and the relationships between them, enabling automatic identification and location of the root causes of defects; it can automatically sort the lines of code changes, locate the root causes of defects, provide reliable suggestions for developers, reduce the time and cost spent by developers, and improve maintenance efficiency and software quality; by removing noise from commits, this invention helps improve the accuracy of tools that identify commits that introduce defects. Attached Figure Description
[0046] Figure 1 This is a flowchart of the diagram construction stage in this invention;
[0047] Figure 2 This is an example diagram of the diagram construction stage in this invention;
[0048] Figure 3 This is a model diagram of the sorting stage of the present invention;
[0049] Figure 4 This is an example diagram of the data annotation stage of the present invention. Detailed Implementation
[0050] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims. It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not intended to limit this application.
[0051] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0052] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "in response to determination," or "includes." Moreover, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process or method. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0053] This invention aims to pinpoint the root cause of defects by analyzing commits that fix them. It consists of two phases: a graph construction phase and a sorting phase. The main application scenarios for this invention are providing suggestions for developers to analyze and fix defect commits, and improving the accuracy of tools that identify commits that introduce defects. In the graph construction phase, this invention constructs a graph based on the relationships between lines of code changes. In the sorting phase, this invention uses deep learning methods to sort all lines of code changes according to the probability that the current line of code is the root cause of the defect, thereby pinpointing the root cause. This method improves the efficiency of developers analyzing code changes and enhances the accuracy of tools that identify commits that introduce defects.
[0054] The method for automatically locating the root cause of defects according to the present invention specifically includes the following steps:
[0055] S1. Obtain code change information c from the commit. Code change information c includes the source code src_code before the change, the source code dst_code after the change, and the modified lines t. Modified lines t include deleted lines. and add lines .
[0056] It should be understood that current software development relies on version control systems to manage source code and track code changes. Version control systems use commits as the basic unit, and each commit saves a snapshot of the entire project at that time.
[0057] Specifically, retrieve the source code (src_code) before the change, the source code (dst_code) after the change, and the deleted lines from the commit log. Added lines Record current code change information c= <src_code,dst_code, , >
[0058] S2. Process the code change information c in the commit, extract the relationships between all modified lines from t, src_code, and dst_code to construct a heterogeneous graph G, such as... Figure 1 As shown.
[0059] S21. Use the javaParser tool to construct abstract syntax trees for src_code and dst_code respectively. The abstract syntax tree corresponding to src_code is: The abstract syntax tree corresponding to dst_code is ;Delete the lines in all modified lines t Mapped to From the nodes, obtain the deleted node. ;Add lines to all modified lines t Mapped to From the nodes, we get the added nodes. .
[0060] In this embodiment, nodes need to be extracted first to serve as nodes in the heterogeneous graph G. Specifically, abstract syntax trees are constructed for src_code and dst_code respectively to obtain... and .right and For any statement in the code, record the line number in the source code corresponding to that line. If any line is deleted... line numbers and If the row numbers of the nodes intersect, then the row should be deleted. Mapped to The deleted line Among the nodes that intersect, the node to be deleted is obtained. Similarly, if any row is added... line numbers and If the row numbers of the nodes in the middle node have an intersection, then the next row should be added. Mapped to The middle and the added line Among the nodes that intersect, additional nodes are obtained. This allows all nodes to be extracted for use in subsequent graph construction steps.
[0061] S22. In the source code src_code before the change and the source code dst_code after the change, based on the deleted nodes... and adding nodes The relationships between them are used to construct corresponding types of graphs, including control flow graphs, data dependency graphs, function call graphs, and class member reference graphs.
[0062] In this embodiment, the deletion node is extracted based on step S21. and adding nodes Construct different types of graphs. Specifically, extract the nodes to be deleted. and adding nodes Different relationships may exist between them, such as control dependencies and data dependencies. Therefore, different kinds of graphs are constructed based on the source code to describe these relationships. In the source code src_code and the modified source code dst_code, based on the deleted nodes... and adding nodes The relationships between the graphs are used to construct corresponding types of graphs. The code analysis tool Joern is used to construct corresponding types of graphs on src_code and dst_code, such as control flow graphs, data dependency graphs, function call graphs, and class member reference graphs.
[0063] It should be understood that Joern, a code analysis tool, is a well-known tool that can generate various types of graphs from source code.
[0064] S23. For each type of graph in the source code src_code before the change and the source code dst_code after the change, use a depth-first search method to extract whether there is a path between the nodes. If a path exists, add an edge of the corresponding type between the corresponding nodes to obtain the graph before the change. And the revised diagram Otherwise, proceed directly to step S24.
[0065] It should be understood that the depth-first search method uses the tool Joern, which can generate various types of graphs from the source code. Determining the relationship between deleting and adding nodes is the task of the depth-first search method.
[0066] In this embodiment, it is necessary to determine whether there are connections between nodes in order to extract edges. Specifically, a depth-first search algorithm is used to extract edges from the graph. For any type of graph, a depth-first search algorithm is used to search... and Does a path exist between them? If and If paths exist between them, add an edge between them, with the edge type corresponding to the current graph type. The same principle applies. After completing this step, for all... You can get their corresponding graphs. ,like Figure 2 As shown. For all You can get their corresponding graphs. .
[0067] Taking the original source code src_code as an example, what was extracted before the change were the deleted nodes. Then, it was determined whether there were any connections between these deleted nodes, and edges were added to obtain the corresponding graph. Therefore, it's necessary to determine if paths exist between the deleted nodes. Specifically, the source code `src_code` includes all types of graphs. A depth-first search is used to search these graph types. If a path exists between any two deleted nodes in any type of graph, an edge is added between these two deleted nodes, with the edge type matching the current graph type. This process is repeated until all pairs of deleted nodes have had their paths checked. Finally, the corresponding graph can be obtained. The final image obtained. All nodes in the array are deleted nodes, but the edge relationships between the deleted nodes are different.
[0068] S24, Judgment Diagram Can the deleted row in the middle node be mapped to the graph? Add a row to the corresponding node, if The deleted row in the middle node can be mapped to If a row is added to the corresponding node, an edge is added between the two nodes to construct a heterogeneous graph G; otherwise, there is no connecting edge between the two nodes.
[0069] In this embodiment, a row mapping algorithm is used for row mapping. Specifically, a row mapping algorithm is used to... and Establish a connection to map the deleted rows to The nodes in This will add a row mapping to From The tool GumTree is used to make a judgment, judging any one Can it be mapped to any If any row is deleted Can be mapped to using row mapping algorithms Then you can corresponding nodes and corresponding nodes Add an edge between them. This will allow you to... and The final heterogeneous graph G is obtained by merging the graphs.
[0070] For example, such as Figure 2As shown, an example graph is given for the graph construction phase. Specifically, in the node extraction step, rows 5 and 12 are mapped to deleted node 1 and deleted node 2, rows 6 and 7 are mapped to added node 1, and row 9 is mapped to added node 2. Similarly, all deleted and added nodes can be extracted. In the step of constructing different types of graphs, different types of graphs are extracted from the source code before and after the change. These graphs include deleted and added nodes, as well as many irrelevant nodes. In this example, the changes only involve the control flow graph and the data dependency graph, therefore... Figure 2 Only these two types of graphs are shown. In the edge extraction step, the corresponding edges are extracted using a depth-first search method. For example, the first deleted node can be traced through the control flow graph to a path leading to the second deleted node, so an edge is added between them, and the edge type is a control flow graph edge. In the row mapping step, it can be found that row 12 can be mapped to row 14, where row 12 corresponds to deleted node 2 and row 14 corresponds to added node 5. Therefore, a row mapping edge is added between deleted node 2 and added node 5, and so on, until the constructed heterogeneous graph G is obtained.
[0071] S3. Input the heterogeneous graph G into the heterogeneous graph attention neural network. For each node in the heterogeneous graph G... Obtain the embedding vector representation corresponding to this node. ,like Figure 3 As shown.
[0072] In this embodiment, the structure of the heterogeneous graph attention neural network is as follows: Figure 3 As shown, this heterogeneous graph attention neural network includes an embedding layer, a node attention layer, and a semantic attention layer. The embedding layer is a codeBERT encoder pre-trained based on Transformer, which can convert the code contained in the graph nodes into their corresponding embedding vector representations. Then, a node attention layer is used to aggregate the embedding of each node and the embeddings of its neighboring nodes in each type of graph. Next, a semantic attention layer is used to aggregate the embeddings of the same nodes corresponding to all types of graphs through an attention mechanism, resulting in the final node embedding vector representation. .
[0073] S31. Using a Transformer-based pre-trained codeBERT encoder to process nodes in a heterogeneous graph G. The corresponding code is encoded and converted into a numerical representation. Then, this encoder converts the numerical representation into a multidimensional vector representation. .
[0074] S32. Map the features of different types of nodes to the same feature space, as shown below:
[0075]
[0076] in, It is the feature vector output by the codeBERT encoder. It is the matrix to be learned. The nodes are obtained through a unified mapping. eigenvectors.
[0077] S33. The heterogeneous graph attention neural network calculates node-level attention scores as follows:
[0078]
[0079] in, It is a normalized node-level attention score, representing the node's... For nodes The degree of importance; Representative node Based on metapath All adjacent nodes, represents the Sigmoid activation function, and || represents the concatenation operator; These are parameters that need to be optimized during training.
[0080] For each type of metapath For nodes The corresponding feature vector can be obtained. As shown below:
[0081] =
[0082] in, It is the normalized attention score.
[0083] Subsequently, the heterogeneous graph attention neural network computes the importance of each type of meta-path. Given a set of meta-paths... The importance of each type of metapath is calculated using the following formula:
[0084]
[0085] in, yes Attention score for this type of meta-path Represents the nodes in the graph. , and These are all parameters to be learned. It is an activation function.
[0086] Normalize the weights of all metapaths to obtain the final normalized weights:
[0087]
[0088] in, This represents the final normalized weights. It should be understood that normalization can effectively eliminate the model's sensitivity to the weight scale; without normalization, it is easy to cause gradient vanishing and gradient exploding.
[0089] Finally, all feature vectors under different types of meta-paths are... Combining these, we obtain the final feature embedding vector representation. .
[0090]
[0091] S4. Represent the node's embedding vector. Input into a sorting neural network to obtain the score of the current node. .
[0092] It should be understood that the so-called sorting neural network is a commonly used network model. Through this sorting neural network, the nodes can be sorted and assigned a score.
[0093] S41. Combine all nodes in the heterogeneous graph G into pairs to obtain node pairs. >
[0094] S42, For each pair of nodes >, compute nodes In the final arrangement, it has higher priority than True probability As shown in the formula below:
[0095]
[0096] S43, For each pair of nodes >, sorting neural networks will all be based on their feature vectors and Assign it a fraction and and calculate the nodes In the final arrangement, it has higher priority than The probability is shown in the following formula:
[0097]
[0098] S44, Ranking Neural Networks Based on True Probability and the calculated probability To update the parameters of the sorting neural network, the loss function of the sorting neural network is as follows:
[0099]
[0100] in, This is the loss function for the sorting neural network.
[0101] It should be noted that the parameters are updated using the Adam optimizer during training, and training stops when the loss change is less than 1%.
[0102] S5. Sort the scores corresponding to all nodes, and the node with the highest score is the node most likely to be the root cause of the current defect.
[0103] This invention aims to automatically locate the root cause of defects. Also known as NEURALSZZ, this method comprises two stages. The first stage is the graph construction stage. In this stage, the invention extracts the lines of code change from the input submission as corresponding graph nodes, extracts control flow graphs, data dependency graphs, function call graphs, and class member reference graphs from the source code before and after the change, and extracts the corresponding edges from these graphs to connect the nodes corresponding to the lines of code change, thus completing graph construction. The second stage is the ranking stage. In this example, the graph extracted in step one is first input into a heterogeneous graph attention neural network. The modified lines contained in the nodes and the different relationships between nodes are converted into embedding representations, which are then passed to the recommendation model. During the training stage, the model pairs all nodes together, assigns a score to each node, and determines the ranking priority of each pair of nodes based on this score. This predicted priority is then compared with the true priority, and the difference between the two is used as the optimization objective to update the model's parameters. The true priority is obtained based on a labeled dataset. During the model's inference phase, all nodes are sorted directly based on the scores assigned to them by the model, and the node most likely to be the root cause of the defect is output. If it is necessary to find the submission that introduced the defect based on the submission that fixed the defect, then the node most likely to cause the defect, output by the model, is input into the appropriate automatic search tool.
[0104] This invention can automatically locate the root cause of defects, provide reliable suggestions to developers when they analyze and submit their work, reduce the time and cost spent by developers, and improve maintenance efficiency and software quality.
[0105] Locating the root cause of a defect requires understanding the code changes in the commit that fixed it. Code changes in a commit consist of two parts: deleted lines of code and newly added lines of code. These changes correspond to two versions of the code, each with its own source files. Based on these source files, we can extract analytical graphs such as control flow graphs and data dependency graphs to depict the different relationships between the changed lines of code.
[0106] The purpose of this invention is to identify the root cause of defects. To this end, a dataset has been constructed. This dataset is based on publicly available datasets of submissions that fix defects and datasets of submissions that introduce defects. (References) Figure 4 This describes an example of constructing a labeled dataset.
[0107] For each deleted line, we use the version control system to backtrack and find the commit that introduced the defect. If the found commit does not correspond to the commit that introduced the defect, then this line is definitely not the root cause of the defect. If the current commit that deleted the line corresponds to the commit that introduced the defect, then we will manually check this line to confirm whether it is the root cause of the defect.
[0108] For example, such as Figure 4 As shown, the commit that fixes the defect is a2a5cb60b09, and the commit that introduced the defect is 4b3a6b87221. Lines 1 and 2 in the CallQueueManager.java file and line 6 in the TestCallQueueManager.java file, after backtracking, correspond to the commit d95c6eb32ce, which is inconsistent with the commit that introduced the defect, so they are directly excluded. The commit corresponding to the deletion line in the TestFairCallQueue.java file is 4b3a6b87221, which is consistent with the commit that introduced the defect, but since this file is a test file and not directly related to the defect to be fixed, it is excluded. Therefore, the root cause of the current defect lies in FairCallQueue.java. FairCallQueue.java has two deletion lines. The first deletion line is related to logging and does not affect the program's execution logic, so it is directly excluded. Therefore, the root cause of the defect is the second deletion line in FairCallQueue.java.
[0109] The effectiveness of this invention in locating the root cause of defects was evaluated using Recall@1, Recall@2, Recall@3, and MFR on the collected dataset. Table 1 illustrates the localization effect of this invention, in which NEURALSZZ achieved the best results across all metrics. NEURALSZZ achieved improvements of 12.8%, 3.12%, and 2.89% in Recall@1, Recall@2, and Recall@3, respectively, and an improvement of 5.51% in MFR.
[0110] Table 1: Effectiveness of Defect Root Cause Locating
[0111]
[0112] After identifying the root cause of the defect, the found root cause is used to find the corresponding submission that introduced the defect. Table 2 illustrates the effectiveness of this invention in this application scenario. NEURLSZZ@k (k=1,2,3) uses the top k nodes output by the ranking model as the root cause of the defect and finds the submission that introduced the defect based on these top k nodes. NEURLSZZ significantly outperforms existing methods in both precision and F1-score. Among all methods, BSZZ has a higher recall rate than this method, but its precision and F1-score are much lower. In practical applications, both precision and recall need to be considered. If the precision is too low, developers need to check many candidates, which greatly reduces developer efficiency and is difficult to apply in practice. Considering that NEURLSZZ improves precision by 121.8% and recall by 40.7% compared to the best benchmark method, this example performs better in identifying submissions that introduce defects.
[0113] Table 2: The effect of identifying defective submissions
[0114]
[0115] The time efficiency of deploying heterogeneous graph attention neural networks and ranking neural network models is also a factor to consider. In the test cases of this test, the model took a total of 93.2 seconds to process all submissions, with an average of 0.59 seconds per submission.
[0116] To better evaluate why NEURLSZZ outperforms other methods, the evaluation results were manually examined. Based on this examination, two main advantages of NEURLSZZ can be summarized: one is its ability to better understand the semantics of changed lines through codeBERT, and the other is its ability to better capture the relationships between changed lines through graph neural networks. To determine whether these two designs truly improve the performance of NEURLSZZ, the performance of two variants of NEURLSZZ, NEURLSZZ-h and NEURLSZZ-c, was studied. NEURLSZZ-h removes the graph neural network layer and directly connects codeBERT to the recommendation model. NEURLSZZ-c replaces codeBERT with the Doc2vec machine learning algorithm. Table 3 shows a performance comparison between NEURLSZZ and these two variants, demonstrating that NEURLSZZ achieves the best performance in most cases.
[0117] Table 3: Performance Evaluation Results of NEURLSZZ and its Variants
[0118]
[0119] This invention is the first to employ deep learning to locate the root cause of defects, comprising two phases: a graph construction phase and a ranking phase. Evaluation results show that NEURLSZZ outperforms baseline methods in locating the root cause of defects. Furthermore, NEURLSZZ can more effectively identify submissions that introduce defects.
[0120] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for automatically locating the root cause of a defect, characterized in that, Includes the following steps: S1. Obtain code change information c from the commit, where c includes the source code src_code before the change, the source code dst_code after the change, and the modified lines t, including deleted lines. and add lines ; S2. Process the code change information c in the submission, extract the relationships between all modified lines from t, src_code, and dst_code to construct a heterogeneous graph G; step S2 includes the following sub-steps: S21. Use the javaParser tool to construct abstract syntax trees for src_code and dst_code respectively. The abstract syntax tree corresponding to src_code is: The abstract syntax tree corresponding to dst_code is ;Delete the lines in all modified lines t Mapped to From the nodes, obtain the deleted node. ;Add lines to all modified lines t Mapped to From the nodes, we get the added nodes. ; S22. In the source code src_code before the change and the source code dst_code after the change, based on the deleted nodes... and adding nodes The relationships between them are used to construct corresponding types of graphs, including control flow graphs, data dependency graphs, function call graphs, and class member reference graphs; S23. For each type of graph in the source code src_code before the change and the source code dst_code after the change, use a depth-first search method to extract whether there is a path between the nodes. If a path exists, add an edge of the corresponding type between the corresponding nodes to obtain the graph before the change. And the revised diagram Otherwise, proceed directly to step S24; S24, Judgment Diagram Can the deleted row in the middle node be mapped to the graph? Add a row to the corresponding node, if The deleted row in the middle node can be mapped to If a row is added to the corresponding node, an edge is added between the two nodes to construct a heterogeneous graph G; otherwise, there is no connecting edge between the two nodes. S3. Input the heterogeneous graph G into the heterogeneous graph attention neural network. For each node in the heterogeneous graph G... Obtain the embedding vector representation corresponding to this node. ; S4. Represent the node's embedding vector. Input into a sorting neural network to obtain the score of the current node. ; S5. Sort the scores corresponding to all nodes, and the node with the highest score is the node that is the root cause of the current defect.
2. The method for automatically locating the root cause of defects according to claim 1, characterized in that, The heterogeneous graph attention neural network includes an embedding layer, a node attention layer, and a semantic attention layer. The embedding layer is a codeBERT encoder pre-trained based on Transformer, which converts the code contained in the graph nodes into their corresponding embedding vector representations. Then, a node attention layer aggregates the embedding of each node with the embeddings of its neighboring nodes; next, a semantic attention layer aggregates the embeddings of the same nodes corresponding to all types of graphs through an attention mechanism to obtain the final node embedding vector representation. .
3. The method for automatically locating the root cause of defects according to claim 1, characterized in that, Step S3 includes the following sub-steps: S31. Using a Transformer-based pre-trained codeBERT encoder to process nodes in a heterogeneous graph G. The corresponding code is encoded and converted into a numerical representation. Then, this encoder converts the numerical representation into a multidimensional vector representation. ; S32. Map the features of different types of nodes to the same feature space, as shown below: in, It is the feature vector output by the codeBERT encoder. It is the matrix to be learned. The nodes are obtained through a unified mapping. eigenvectors; S33. The heterogeneous graph attention neural network calculates the attention score at the node level, and its expression is: in, It is a normalized node-level attention score, representing the node's... For nodes The degree of importance; Representative node Based on metapath All adjacent nodes, represents the Sigmoid activation function, and || represents the concatenation operator; These are parameters that need to be optimized during training; For each type of metapath compute nodes corresponding feature vector As shown below: = in, It is the normalized attention score; Subsequently, the heterogeneous graph attention neural network computes the importance of each type of metapath, given a set of metapaths. The formula for calculating the importance of each type of metapath is: in, yes Attention score for this type of meta-path Represents the set of nodes in the graph. , and These are all parameters to be learned. It is an activation function; Normalize the weights of all metapaths to obtain the final normalized weights: in, Represents the final normalized weights; All feature vectors under different types of metapaths By combining these elements, we obtain the final feature embedding vector representation. Its expression is: 。 4. The method for automatically locating the root cause of defects according to claim 1, characterized in that, Step S4 includes the following sub-steps: S41. Combine all nodes in the heterogeneous graph G into pairs to obtain node pairs. >; S42, For each pair of nodes >, compute nodes In the final arrangement, it has higher priority than True probability As shown in the formula below: S43, For each pair of nodes >, sorting neural networks will all be based on their feature vectors and Assign it a fraction and and calculate the nodes In the final arrangement, it has higher priority than The probability is shown in the following formula: S44, Ranking Neural Networks Based on True Probability and the calculated probability To update the parameters of the sorting neural network, the loss function of the sorting neural network is as follows: in, This is the loss function for the sorting neural network.