Software defect automatic positioning method based on heterogeneous graph representation learning

By constructing a heterogeneous graph representation learning method, integrating various information from software projects, and utilizing attention mechanisms and convolutional neural networks, the problem of low efficiency in existing software defect localization is solved, achieving more efficient defect localization and accurate recommendation.

CN115757141BActive Publication Date: 2026-05-29HANGZHOU DIANZI UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU DIANZI UNIV
Filing Date
2022-11-21
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing software defect localization methods make poor use of various types of information, resulting in low localization efficiency, especially posing challenges in class imbalance problems.

Method used

We construct a method based on heterogeneous graph representation learning, which acquires and integrates textual and structural information of test cases and methods, aggregates features using an attention mechanism, and combines convolutional neural networks for defect prediction.

Benefits of technology

It effectively improved the defect localization effect, overcame the class imbalance problem, and improved the effectiveness of feature learning and localization accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115757141B_ABST
    Figure CN115757141B_ABST
Patent Text Reader

Abstract

The application discloses a kind of software defect automatic positioning methods based on heterogeneous graph representation learning.The method is first obtained from the required data in project, by abstracting various data into different types of vertex and edge, constructs a heterogeneous graph;Then the information in heterogeneous graph is aggregated by three modules, and the feature representation of each method in source program is obtained;Finally, a prediction model is constructed based on convolutional neural networks (CNN) to calculate the probability of defects existing in each method, and the defect positioning result is obtained.At the same time, the application introduces a resampling strategy, which effectively overcomes the class imbalance problem in the problem.Through the method of the application, the effectiveness of feature learning and the accuracy of defect positioning can be effectively improved, which has very important practical significance for reducing software development and maintenance cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software maintenance, and in particular to a method for locating software defects based on heterogeneous graph representation learning. Background Technology

[0002] Software plays a vital role in people's lives. It is widely used in various fields, such as healthcare, gaming, and aerospace. However, the inherent complexity of software makes software defects inevitable. Once a software defect is discovered, developers need to pinpoint its location and fix it. Unfixed software defects not only affect the user experience but also cause significant losses of human and material resources. Statistics show that approximately 42% of software development funding is allocated to work related to software defects, and the cost of discovering defects during the maintenance phase is 100 times that of the development phase. Therefore, researching how to help developers fix defects better and faster is of great significance.

[0003] Existing defect localization methods can be categorized into two types based on whether test cases need to be executed: static defect localization methods and dynamic defect localization methods. Static defect localization methods analyze defect reports and program code to extract features, use specific models to identify suspicious program modules, and recommend them to developers to assist in localization. Dynamic defect localization methods collect execution information and results of test cases to analyze the internal structure of the program under test to determine the possible location of defective statements within the program. Compared to static defect localization methods, dynamic defect localization methods rely on test case coverage information to locate defects and generally achieve better results. Summary of the Invention

[0004] The purpose of this invention is to address the problem of low utilization of various types of information in existing software defect localization methods, and to provide an automatic software defect localization method based on heterogeneous graph representation learning, which can effectively help developers locate software defects.

[0005] To achieve the above objectives, the technical solution of the present invention is as follows:

[0006] Step (1) Obtain the data required for defect location:

[0007] Sub-step 1-1: Obtain the set of test cases T = (test1, test2, ..., test...) from the target project. n ), and the set of methods contained therein M = (method1, method2, ..., method m ), where n and m represent the number of test cases and the number of methods, respectively.

[0008] Sub-steps 1-2 use the open-source tools javaagent and ASM to dynamically instrument the code, that is, to insert specific code into each method. Once the method is called by the test case, the method name will be printed out. Finally, the code coverage information of the test case can be obtained from the output information.

[0009] Sub-steps 1-3 involve retrieving the project's historical logs from GitHub and extracting historical modification information. If two methods... a and method b If (a≠b) is modified in the same version, it is represented as a pair mpair= <method a ,method b >, all pairs form the set MP.

[0010] Sub-steps 1-4 involve using the open-source tool TinyPDG to obtain the call relationships between methods in the target code. If two methods... a and method b If there is a calling relationship between (a≠b), it is represented as a pair cpair= <method a ,method b > indicates method a The method was called b All pairings form the set CP.

[0011] Step (2) processes both the method set and the test case set in two different ways:

[0012] Sub-step 2-1: Treat all method source code and test case source code as text, use the BytePair Encoding (BPE) algorithm to segment the text, and construct a keyword dictionary Tok = {token1, token2, ..., token}. len1}, where len1 represents the number of keywords in the dictionary. Each method and test case can be represented as a sequence of tokens.

[0013] Sub-step 2-2: Use the open-source tool javaparser to convert all method source code and test case source code into an abstract syntax tree (AST). The nodes contained in all the ASTs form a set Nod = (node1, node2, ..., node...). len2 ), where len2 represents the number of nodes.

[0014] Step (3): Using word2vec word embedding technology, train the text of all methods and test cases in the project to obtain each token. i Word vectors of (i = 1, 2, ..., len1) Simultaneously, node2vec node embedding technology is used to train all abstract syntax trees, obtaining each node. j A vector (j = 1, 2, ..., len2)

[0015] Step (4) resamples the subclass samples to make the number of failed test cases and successful test cases, and the number of defective methods and non-defective methods consistent. In addition, the coverage relationship between the newly added methods and test cases is constructed, that is, the coverage information of the original methods and test cases is copied.

[0016] Step (5) Construct a heterogeneous graph G = (V, E), where V represents the set of vertices and E represents the set of edges, and V contains two types of vertices v. method and v test E contains four types of edges e pass e fail e modify and e call .

[0017] Sub-step 5-1: Abstract each method in M ​​into a vertex v method ∈V, its attribute is represented as attr(v method ) = (vector mtext vector mast ),in This is a vector representation of the method's textual information. This is a vector representation of the method's structural information, where len3 represents the number of tokens contained in the method text and len4 represents the number of nodes contained in the abstract syntax tree corresponding to the method.

[0018] Sub-step 5-2: Abstract each test case in T into a vertex v. test ∈V, its attribute is represented as attr(v test ) = (vector ttext vector tast ),in This is a vector representation of the test case text information. This is a vector representation of the test case structure information, where len5 represents the number of tokens contained in the test case text and len6 represents the number of nodes contained in the abstract syntax tree corresponding to the test case.

[0019] Sub-step 5-3: If a passed test case covers a certain method, then add an edge e between the two vertices. pass ∈E; if a failed test case covers a method, add an edge e between the two vertices. fail ∈E.

[0020] Sub-step 5-4: Based on the pairings in set MP, add an edge e between the corresponding method vertices. modify ∈E; Based on the pairings in set CP, add an edge e between the corresponding method vertices. call ∈E.

[0021] After the above steps, various types of information were successfully integrated into a heterogeneous diagram.

[0022] Step (6) For vertex v∈V, the attribute vector representation of vertex v is formed by averaging the sum of all dimensions of all vectors. attr .

[0023] Step (7) In graph G, for vertex v, the attribute vectors of all neighboring vertices connected to this vertex by a certain type of edge are summed and averaged to form the type vector representation of this vertex. Finally, four types of vector representations are obtained, namely vector... pass vector fail vector modify vector call .

[0024] Step (8) For a vertex v∈V, the attribute vector representation and the four types of vector representations of the vertex are aggregated using an attention mechanism to obtain the final vector of the vertex using this method. final .

[0025] Step (9) constructs a prediction model based on Convolutional Neural Networks (CNN), where the final vector representation of all vertices is used as the input of the model, and finally obtains the doubt score of each method, that is, the probability that the method has defects.

[0026] Step (10) sort all methods in descending order of suspicious scores to obtain the final recommendation result.

[0027] This invention proposes an automatic software defect localization technique based on heterogeneous graph representation learning. Compared with existing software defect localization techniques, this invention has the following advantages: (1) Extracting various types of information contained in methods and test cases to construct heterogeneous graphs can effectively improve defect localization results. (2) Using attention mechanisms to aggregate different types of vectors can effectively improve the effectiveness of feature learning. (3) Introducing a resampling strategy can effectively overcome the class imbalance problem in the problem. Attached Figure Description

[0028] Figure 1 This is a flowchart of the software defect automatic localization technology based on heterogeneous graph representation learning according to the present invention. Detailed Implementation

[0029] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0030] Data source acquisition: The original dataset used in this experiment comes from the open-source dataset Defects4j (version 1.2.0), which collects 395 bugs from 6 open-source projects: jfreechart, closure-compiler, commons-lang, commons-math, mockito, and joda-time.

[0031] The following is in conjunction with the appendix Figure 1 This invention provides a detailed description of an automatic software defect localization method based on heterogeneous graph representation learning, comprising the following steps:

[0032] Step (1) Obtain the data required for defect location:

[0033] 1-1 Obtain the test case set T = (test1, test2, ..., test2) from the target project n The set of methods M = (method1, method2, ..., method...) m ), where n and m represent the number of test cases and methods, respectively.

[0034] 1-2 Use open-source tools javaagent and ASM to dynamically instrument the code, that is, insert specific code into each method. Once the method is called by the test case, the method name will be printed. Finally, the code coverage information of the test case can be obtained from the output information.

[0035] 1-3 Obtain the project's historical logs from GitHub and extract the project's historical modification information. If two methods... a and method b If (a≠b) is modified in the same version, it is represented as a pair mpair= <method a ,method b >, all pairs form the set MP.

[0036] 1-4 Use the open-source tool TinyPDG to obtain the call relationships between methods in the target code. If two methods... a and method b If there is a calling relationship between (a≠b), it is represented as a pair cpair= <method a ,method b > indicates method a The method was called b All pairings form the set CP.

[0037] Step (2) processes both the method set and the test case set in two different ways:

[0038] 2-1 Treat all method source code and test case source code as text, use the Byte Pair Encoding (BPE) algorithm to segment the text, and construct a keyword dictionary Tok = {token1, token2, ..., token}. len1}, where len1 represents the length of the dictionary. Each method and test case can be represented as a sequence of tokens.

[0039] 2-2 Use the open-source tool javaparser to convert all method source code and test case source code into an Abstract Syntax Tree (AST). All nodes contained in the AST form a set Nod = (node1, node2, ..., node...). len2 ), where len2 represents the number of nodes.

[0040] Step (3): Using word2vec word embedding technology, train the text of all methods and test cases in the project to obtain each token. i Word vectors of (i = 1, 2, ..., len1) Simultaneously, node2vec node embedding technology is used to train all abstract syntax trees, obtaining each node. j A vector (j = 1, 2, ..., len2) In this invention, the dimensions of word vectors and node vectors are set to 128.

[0041] Step (4) resamples the subclass samples to make the number of failed test cases and successful test cases, and the number of defective methods and non-defective methods consistent. In addition, the coverage relationship between the newly added methods and test cases is constructed, that is, the coverage information of the original methods and test cases is copied.

[0042] Step (5) Construct a heterogeneous graph G = (V, E), where V represents the set of vertices and E represents the set of edges, and V contains two types of vertices v. method and v test E contains four types of edges e pass e fail e modify and e call .

[0043] 5-1 Abstract each method in M ​​into a vertex v method ∈V, its attribute is represented as attr(v method ) = (vector mtext vector mast ),in Vector representation of text information The vector representation of structural information, len3 represents the number of tokens contained in the method text, and len4 represents the number of nodes contained in the abstract syntax tree corresponding to the method.

[0044] 5-2 Abstract each test case in T into a vertex v test ∈V, its attribute is represented as attr(v test ) = (vector ttext vector tast ),in It is represented as a vector representation of text information. The vector representation of structural information, len5 represents the number of tokens contained in the test case text, and len6 represents the number of nodes contained in the abstract syntax tree corresponding to the test case.

[0045] 5-3 If a passed test case covers a certain method, add an edge e between the two vertices. pass ∈E; if a failed test covers a method, add an edge e between the two vertices. fail ∈E.

[0046] 5-4 Based on the pairings in set MP, add an edge e between the corresponding method vertices. modify ∈E; Based on the pairings in set CP, add an edge e between the corresponding method vertices. call ∈E.

[0047] Step (6) For vertex v∈V, the attribute vector representation of vertex v is formed by averaging the sum of all dimensions of all vectors. The specific calculation formula is as follows;

[0048]

[0049] Where f0(v) represents the attribute vector of vertex v after aggregation, vector text The text information vector representation of vertex v, i.e., vector mtext and vector ttext vector ast The structural information vector representation of vertex v, i.e., vector mast and vector tast .

[0050] Step (7) In graph G, for vertex v, the attribute vectors of all neighboring vertices connected to this vertex by a certain type of edge are summed and averaged to form the type vector representation of this vertex. Finally, four type vector representations are obtained, and the specific calculation formulas are as follows:

[0051]

[0052] Where k = 1, 2, 3, 4 correspond to edge type e respectively. pass e fail e modify and e call N k (v) represents the set of all vertices connected to vertex v through edges of type k, f k (v) represents the type vector of vertex v formed by aggregating all vertices in the set.

[0053] Step (8) For a vertex v∈V, the attribute vector representation and the four types of vector representations of the vertex are aggregated using an attention mechanism to obtain the final vector representation of the vertex using this method. The specific calculation formula is as follows:

[0054]

[0055]

[0056] where vector final The final vector representation of the node in the representation method, α jThis represents the weight of each type of information learned by the attention mechanism. This indicates a cascading operation.

[0057] Step (9) constructs a prediction model based on Convolutional Neural Networks (CNN), where the final vector representation of all method vertices is used as the model input. The features contained in the method vector representation are learned, and finally, the sigmoid function is used to regularize the CNN output to obtain the suspicion score for each method, i.e., the probability that each method has a defect. The CNN model of this invention contains three convolutional layers and three fully connected layers. The dimensions of the convolutional kernels in the three convolutional layers are set to 16, 16, and 32, respectively, and the dimension of each fully connected layer is 1024.

[0058] Step (10) Sort all methods in descending order of suspicious scores to obtain the final recommendation result.

[0059] The experiment in Example 1 demonstrates that:

[0060] To demonstrate the effectiveness of this invention, TOP-k, Mean First Rank (MFR), and Mean Average Rank (MAR) were used as evaluation metrics. The invention's technique was compared with the more advanced software defect localization techniques CNNFL, FLUCCS, and GRACE on the public dataset Defects4j (version 1.2.0). The experimental results are shown in Table 1.

[0061] Table 1

[0062]

[0063]

Claims

1. A method for automatic software defect localization based on heterogeneous graph representation learning, characterized in that, Includes the following steps: Step 1: Obtain the data required for defect location; Sub-step 1-1 Obtain the test case set from the target project and the set of methods it contains ,in and These represent the number of test cases and methods, respectively. Sub-steps 1-2 use the open-source tools javaagent and ASM to dynamically instrument the code: insert specific code into each method, and once the method is called by the test case, the method name will be printed. Finally, the code coverage information of the test case can be obtained based on the output information. Sub-steps 1-3: Obtain the project's historical logs from GitHub and extract the project's historical modification information; if two methods... and ( If modified in the same version, it is represented as a pair. All pairs form a set ; Sub-steps 1-4 use the open-source tool TinyPDG to obtain the call relationships between methods in the target code. If two methods... and ( If there is a calling relationship between them, it is represented as a pair. ,express Called ; All pairs form a set ; Step 2: Process both the method set and the test case set in two different ways; Step 3: Use the word2vec word embedding method to train the word embedding on all methods and test case texts in the project, obtaining each... word vectors ; The node2vec node embedding method is used to train all abstract syntax trees to obtain each node. vector ;in Indicates the length of the dictionary, where Indicates the number of nodes; Step 4: Resample the subclass samples to make the number of failed test cases and successful test cases, as well as the number of defective methods and non-defective methods consistent. In addition, copy the coverage information of the original methods and test cases to build the coverage relationship between the newly added methods and test cases. Step 5, construct the heterogeneous graph ,in Represents the set of vertices. Let represent the set of edges, and Includes two types of vertices and , It contains four types of edges , , and ; Sub-step 5-1 Each method in the process is abstracted as a vertex. Its attributes are represented as ; in Vector representation of text information Vector representation of structural information The text containing the representation method quantity, The representation method corresponds to the number of nodes contained in the abstract syntax tree; Sub-step 5-2 Each test case in the process is abstracted as a vertex. Its attributes are represented as ,in It is represented as a vector representation of text information. , representing the vector representation of structural information, This indicates the text contained in the test case. quantity, This indicates the number of nodes contained in the abstract syntax tree corresponding to the test case; Sub-step 5-3: If a passed test case covers a method, add an edge between the two vertices. If a failed test overrides a method, add an edge between the two vertices. ; Sub-step 5-4 Based on the set In the pairing, an edge is added between the corresponding method vertices. According to the set In the pairing, an edge is added between the corresponding method vertices. ; Step 6, for vertices Vertices are formed by averaging the sums of all vectors along their dimensions. The attribute vector representation; Step 7, in the figure In the middle, for the vertex The attribute vectors of all neighboring vertices connected to the vertex by a certain type of edge are summed and averaged to form the type vector representation of the vertex; finally, four types of vector representations are obtained. Step 8, for vertices The attribute vector representation and the four types of vector representations of the vertex are aggregated using an attention mechanism to obtain the final vector representation of the vertex. Step 9: Build a prediction model based on CNN, where the final vector representation of all method vertices is used as the input of the model. Learn the features contained in the method vector representation, use sigmoid to regularize the output of CNN, and obtain the suspicion score of each method, that is, the probability that each method has a defect. Step 10: Sort all methods in descending order according to the suspicious scores obtained in Step 9 to obtain the final recommendation results.

2. The automatic software defect localization method based on heterogeneous graph representation learning according to claim 1, characterized in that... Step 2 includes the following sub-steps: Sub-step 2-1: Treat all method source code and test case source code as text, use the BPE algorithm to segment the text, and build a keyword dictionary. ,in Indicates the length of the dictionary; each method and test case is represented as a sequence of tokens. Sub-step 2-2: Use the open-source tool javaparser to convert all method source code and test case source code into an Abstract Syntax Tree (AST); all nodes contained in the AST form a set. ,in Indicates the number of nodes.

3. The automatic software defect localization method based on heterogeneous graph representation learning according to claim 1 or 2, characterized in that... The formula for calculating the attribute vector representation in step 6 is as follows: ; in Represents the vertices after aggregation Attribute vectors, Represents vertices The text information vector representation, i.e. and , Represents vertices The structural information vector representation, i.e. and .

4. The automatic software defect localization method based on heterogeneous graph representation learning according to claim 1, characterized in that... The formula for calculating the type vector representation in step 7 is as follows: ; in Corresponding to edge types , , and , Indicates passing through the first Types of edges and vertices The set of all connected vertices. This represents the vertex formed by aggregating all vertices in the set. A vector of type.

5. The automatic software defect localization method based on heterogeneous graph representation learning according to claim 3, characterized in that... The formula for calculating the type vector representation in step 8 is as follows: ; ; in The final vector representation of the node in the representation method. This represents the weight of each type of information learned by the attention mechanism. This indicates a cascading operation.