Software Defect Localization Method Based on Context-Aware Code Translation and Feature Fusion

By constructing a multi-layer matching module and a fully connected network, and combining traditional information retrieval with context-aware code translation, the problem of insufficient semantic matching in software defect localization is solved, thereby improving the accuracy of defect localization and the stability of the model.

CN118916263BActive Publication Date: 2026-01-06HANGZHOU DIANZI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410879574.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2026-01-06
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

Existing software defect location technologies suffer from lexical mismatch issues in semantic matching between defect reports and source files, which limits the accuracy of location, especially due to a lack of in-depth mining of source file information.

Method used

A three-layer matching module is constructed, consisting of information retrieval, shallow semantics of source files, and deep semantics. By combining traditional information retrieval features, context-aware code translation, and feature fusion with a fully connected network of dense blocks and transition blocks, the accuracy of defect localization is improved.

Benefits of technology

By using rich feature representation and semantic understanding, the accuracy of defect localization is improved, overcoming the problem of insufficient feature representation in existing technologies, and enhancing the stability of the model and gradient propagation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916263B_ABST
    Figure CN118916263B_ABST
Patent Text Reader

Abstract

The application discloses a software defect positioning method based on context-aware code translation and feature fusion. The application firstly extracts different types of information retrieval features from defect reports and source files, and uses a linear model containing dense blocks and transition blocks to associate different features of information retrieval; then constructs a shallow semantic information and defect report matching module of the source file and a deep semantic information and defect report matching module of the source file, converts the natural language description of the code of the source file into the deep semantic information of the source file, and uses the deep semantic information and the defect report for semantic matching; finally, a fusion module is constructed to fuse the results of each module to obtain the final positioning result. The application overcomes the limitation of insufficient feature representation of the source file in the current defect positioning technology, enriches the feature expression ability of the source file, helps the model to better understand the source file, and thus improves the accuracy of the final prediction of the defect positioning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of software defect localization, specifically involving a software defect localization method based on context-aware code translation and feature fusion. Background Technology

[0002] With technological advancements and increasing demands for software, the scale and complexity of software are also rising. Software is becoming increasingly uncontrollable, and defects can cause it to malfunction. Development teams invest significant manpower and time in software maintenance. Defect localization is a crucial step in software maintenance; only after defects are located can subsequent steps such as repair be completed. Manual defect localization has several drawbacks: firstly, it is time-consuming—a survey indicated that program debugging and fault location can account for up to 50% of developers' work time; secondly, it relies heavily on developers' experience and expertise. To reduce the cost of software maintenance and shorten problem-solving time, researchers have proposed automated software defect localization technologies.

[0003] In existing technologies, a mainstream approach ranks source files based on their relevance to defect reports, helping developers automatically identify potentially defective files. This software defect localization technology can be broadly categorized into two types: one is information retrieval-based defect localization, which utilizes keyword matching between defect reports and source files; the other is deep learning-based defect localization, which encodes defect reports and source files into embedded representations and then calculates the similarity between vectors. Traditional information retrieval-based defect localization treats both defect reports and source files as plain text, with keyword similarity within the text being the primary basis for localization. Therefore, this method has the following drawbacks: there is a lexical mismatch between the natural language text in the defect report and the programming language in the source file; it is sensitive to code changes—the same code logic can be written differently, leading to textual differences and affecting the accuracy of localization. Benefiting from the development of deep learning, researchers have turned their attention to it. Deep learning-based defect localization involves converting the text of the defect report and source file into corresponding vectors using word embedding techniques. These vectors are then fed into a deep learning model to obtain vectors representing their respective semantics, and finally, the similarity between the vectors is calculated. Compared to traditional information retrieval, the biggest advantage of deep learning is its ability to capture semantic information through the model. Recent work has also demonstrated that deep learning technology can effectively improve the accuracy of defect localization. These works attempt various methods to capture the semantics of defect reports and source files as much as possible.

[0004] Although deep learning models outperform traditional methods in acquiring the semantics of defect reports and source files, most current work focuses on the textual information of the source files. For example, the inventor's previous patent CN202310441116.8, while reasonable in its defect localization and able to solve the problem of word mismatch between defect reports and source files, still lacks deeper mining of source file information, thus limiting the performance of the model. Summary of the Invention

[0005] The purpose of this invention is to address the shortcomings of existing technologies by proposing a software defect localization method based on context-aware code translation and feature fusion. This method requires the construction of a feature matching module for information retrieval and defect reports, a module for matching the text of the source file (referred to as the shallow semantics of the source file) and defect reports, and a module for matching the natural language description of the code in the source file (referred to as the deep semantics of the source file) and defect reports. Finally, the matching results of the three modules are fused to improve the accuracy of defect localization.

[0006] In a first aspect, the present invention provides a software defect localization method based on context-aware code translation and feature fusion, specifically including the following steps:

[0007] Step 1: Obtain the defect report and source files;

[0008] Step 2: Construct a module for matching traditional information retrieval with defect reports:

[0009] Step 2.1: Based on professional knowledge in the field of software engineering, extract the traditional information retrieval features of the defect report and source file in Step 1. The features include rVSM (Vector Space Model) score, collaborative filtering score, stack trace score, cyclomatic complexity, proximate cause of defect fix, and defect fix frequency.

[0010] Step 2.2: Input the traditional information retrieval features obtained in Step 2.1 into the fully connected network DenseNet to obtain the matching score wide_score of the source file and defect report at the traditional information retrieval level; the fully connected network DenseNet includes dense blocks and transition blocks. The dense blocks are composed of multiple layers, and the output dimension of each layer is the same. In the forward propagation, the output of each layer is used as the input of the subsequent layer; the transition blocks are used to control the complexity of the model;

[0011] Step 3: Construct a module for matching shallow semantic information of source files with defect reports.

[0012] Step 3.1: Obtain two types of information from the defect report: summary and description. From the source file, obtain program information and snippets information. The program information includes four types of structural information: class name, method name, attribute name, and local variable name. The snippets information consists of the various segments divided after the source file has undergone text preprocessing.

[0013] Preferably, the preprocessing includes text normalization, stop word removal, and stemming.

[0014] Step 3.2: Match the summary and description of the defect report with the program information and fragment information of the source file pairwise, and calculate the matching scores of summary-program information (summary_infos), summary-fragment information (summary_snps), description-program information (desc_infos), and description-fragment information (desc_snps), which are used as the shallow semantic score (shallow_semantic).

[0015] Step 4: Construct a module for matching deep semantic information of source files with defect reports.

[0016] Step 4.1: Use a compiler and decompiler to convert the text in the source file into a sequence of code instructions;

[0017] Step 4.2: Utilize context-aware code translation technology to translate the instruction sequence into a natural language description, which is the deep semantic information (SMI) of the source file. trans );

[0018] Specifically, step 4.2 includes the following procedures:

[0019] Step 4.2.1: Construct translation rules, and then classify instruction sequences into four categories based on the interaction between the instruction sequence and the local variable array or operand stack:

[0020] Instructions that interact only with the operand stack, instructions that interact only with the local variable array, instructions that interact with both the operand stack and the local variable array, and instructions that do not interact with either the operand stack or the local variable array.

[0021] Step 4.2.2, Top-down static traversal instruction sequence:

[0022] Starting from the entry point of the code, each instruction is statically traversed downwards step by step to simulate the execution process of the instructions; during the traversal, each instruction is converted into the corresponding translation result according to the constructed translation rules;

[0023] Step 4.2.3: During the traversal, collect different context information according to the category to which each instruction belongs; the context information includes constants, local variables, and data and control dependencies with other instructions; use the collected context information to update the translation rules of the current or other related instructions;

[0024] Step 4.2.4: After traversing all the instructions, the transformation result of the instruction sequence is obtained. This transformation result can reflect the deep semantic information of the source code.

[0025] Step 4.3: After matching the summary and description of the defect report in Step 3.1 with the deep semantic information of the source file, calculate two matching scores, summary-instruction information (summary_trans) and description-instruction information (desc_trans), as the deep semantic score deep_semantic.

[0026] Step 5: Results of the fusion matching module:

[0027] Step 5.1: Concatenate shallow_semantic and deep_semantic, and put the concatenation result into a fully connected layer to obtain the total semantic score semantic_score;

[0028] Step 5.2: Combine the total semantic score (semantic_score) obtained in Step 5.1 with the matching score (wide_score) between the source file and the defect report at the traditional information retrieval level obtained in Step 2.2 to obtain the final similarity score between the defect report and the source file.

[0029] Step 6: Sort the source files in descending order based on the final similarity score, and then recommend the sorted list of source files to the developers to assist in defect localization.

[0030] Secondly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the above-described method.

[0031] Compared with the prior art, the present invention has the following beneficial effects:

[0032] 1. Current defect localization techniques mostly focus on the textual information of the source file, lacking deeper analysis of its details, thus limiting model performance. In contrast, this invention uses context-aware code translation technology to translate the instruction sequences of the source file into natural language descriptions, supplementing the semantic information of the source file. This overcomes the limitations of current defect localization techniques that rely on insufficient feature representation of the source file.

[0033] 2. By using a linear model containing dense blocks and transition blocks, different features of information retrieval are associated. The output of each layer is connected to the subsequent layers. This allows low-level features in the network to be directly passed to higher layers, thus avoiding feature loss and information bottleneck problems. Furthermore, this feature reuse helps to enhance gradient propagation and improve the stability of the model.

[0034] 3. This invention considers both the traditional information retrieval features and the semantic features of the source document. These two features complement each other, and fusing them enriches the feature representation capability of the source document, helping the model to better understand the source document, thereby improving the accuracy of the final defect location prediction. Attached Figure Description

[0035] Figure 1 A flowchart of a software defect localization method based on context-aware code translation and feature fusion;

[0036] Figure 2 This is a diagram of the dense block structure of the present invention;

[0037] Figure 3 This is a diagram of the DenseNet fully connected network architecture of the present invention.

[0038] Figure 4 Architecture diagram of the module for matching shallow semantic information of source files with defect reports;

[0039] Figure 5 Classify the instructions;

[0040] Figure 6 Here is a flowchart of the instruction translation algorithm;

[0041] Figure 7 Architecture diagram of the module for matching deep semantic information of source files with defect reports. Detailed Implementation

[0042] The present invention will be further explained below with reference to the accompanying drawings;

[0043] like Figure 1 As shown, a software defect localization method based on context-aware code translation and feature fusion is presented, taking defect reports and data as input. Specifically, it includes the following steps:

[0044] Step 1: Obtain the defect report and source files;

[0045] Step 2: Construct a module for matching traditional information retrieval with defect reports.

[0046] Step 2.1: Based on domain knowledge in software engineering, extract six types of features: rVSM score, collaborative filtering score, stack trace score, cyclomatic complexity, proximate cause of defect fixes, and defect fix frequency. The calculation process for their corresponding scores is as follows:

[0047] rVSM score

[0048] The rVSM score represents defect reports and source documents as vectors of term weights. The weight w is the weight of each word t in document d. i It is calculated based on term frequency (TF) and inverse document frequency (IDF), using the following formula:

[0049]

[0050] In the formula, f t,d This represents the number of times word 't' appears in document 'd', #docs refers to the total number of documents in the corpus, and d t This represents the total number of documents containing the word 't'. After obtaining the weight of each word, we can represent the vector corresponding to document 'd' using the following formula.

[0051]

[0052] Cosine similarity was used to measure the similarity score between defect report r and source file s.

[0053]

[0054] We also need to combine the length score of the source file with the result of the cosine similarity, using the following formula to calculate the length score of the source file:

[0055]

[0056] The `#term` parameter represents the number of words in each source file, and it is input into the normalization function `Nor(x)`. Assume we have an array A = {a1, a2, ..., a...}. n The minimum and maximum values ​​in array A are a, a, and a, respectively. mi n and a max The standardized function Nor(x) is as follows:

[0057]

[0058] Finally, the rVSM scores for defect report r and source file s are as follows:

[0059] rVSM(r,s)=cos(r,s)*lengthScore(#term) (6)

[0060] Collaborative filtering score

[0061] Given a current defect report r and a source file s, before(r,s) represents the set of defect reports preceding r and related to s. The collaborative filtering score cf(r,s) calculates the textual similarity between the text of r and the summaries of all defect reports in before(r,s), as shown in the following formula:

[0062] cf(r,s)=cos(r,before,s)) (7)

[0063] ● Cyclic complexity

[0064] Cyclomatic complexity measures code complexity. In this work, the cyclomatic complexity cc(s) is calculated using the Lizard tool. The calculation formula is as follows:

[0065] cc(s)=E-N+2 (8)

[0066] Where E and N represent the number of edges and nodes in the CFG, respectively.

[0067] • Stack trace

[0068] Some defect reports documented stack trace information of code execution errors, which was utilized in this work. We used regular expressions to extract valid stack trace information and obtained the stack trace-related score st(r,s) using the following formula:

[0069]

[0070] • Latest time of defect fix

[0071] last(r,s) represents the most recently repaired defect, and last(r,s)∈before(r,s). The time-related score fr(r,s) of the most recently repaired defect is obtained using the following formula:

[0072]

[0073] Where r.month represents the month in which defect report r was generated, and s.month represents the month in which the source file s was last repaired before defect report r was created.

[0074] ●Defect repair frequency

[0075] Because frequently modified source files are more likely to contain defects, a defect repair frequency was used in this work. We use the following formula to represent the defect repair frequency ff(r,s):

[0076] ff(r,s)=|before(r,s)| (11)

[0077] Step 2.2: After obtaining the scores of the six software-specific information retrieval features, we concatenate them to obtain the input vector, which is then input into the fully connected network DenseNet. The output of the fully connected network DenseNet is the wide_score, which represents the matching score between the source file and the defect report at the traditional information retrieval level.

[0078] IR_features(r,s)=[rVSM(r,s);cf(r,s);cc(s);st(r,s);fr(r,s);ff(r,s)](12)

[0079] wide_score=DenseNet(IR_features(r,s)) (13)

[0080] The network uses dense blocks and transition blocks to combine the six features. A dense block consists of multiple layers, each using a consistent number of output sizes (each layer has the same output dimension), f(x) i ) represents the i-th layer, x i This is the input to the i-th layer. During forward propagation, the output of each layer serves as the input to the next layer. Therefore, for the n-th layer, its input is as follows, and the architecture of the dense block is as follows: Figure 2 As shown.

[0081] x n =f(x) n-1 )+x n-1 (14)

[0082] Each layer implements a linear transformation and activation function, as shown in Equation 15.

[0083] f n (x n ) = ReLu(FC(x n (15)

[0084] Each dense block increases the output size. Suppose we define a dense block with 10 layers, each with an output size of 2. When the input size of this dense block is 2, the final output size is 2 + 2 * 10 = 22. Therefore, using too many dense blocks makes the model complex, so transition blocks are introduced to control the model's complexity. A transition block is denoted by TransitionBlock(x), where x represents the input of the transition block. The transition block consists of fully connected layers and ReLU layers, as shown in Equation 16.

[0085] TransitionBlock(x)=ReLu(FC(x)) (16)

[0086] The overall architecture of the fully connected network DenseNet is as follows: Figure 3 As shown; the fully connected network DenseNet includes dense blocks and transition blocks connected in sequence, and the number of dense blocks and transition blocks is equal. In this embodiment, the fully connected network DenseNet includes 3 dense blocks and 3 transition blocks.

[0087] Step 3: Construct a module for matching shallow semantic information of source files with defect reports.

[0088] Step 3.1: For defect reports, the summary and description sections are used; for source files, all content, including code and comments, is used. This application also considers the structured information of the source files. The four types of structured program information in the source files—class names, method names, attribute names, and local variables—are obtained through AST parsing. In the data preprocessing stage, all text is segmented into individual words, and then these words are filtered. Punctuation marks, numbers, stop words, and keywords in the programming language are filtered out. It is important to note that the word sequences contain compound words with specific meanings, such as "getMax". During data preprocessing, these compound words are split into forms such as 'get' and 'max', while retaining the original words. Each source file is split into fragments of the same size. Before being input into the model, the words are converted into vectors. This work uses a word2vec model with skip-grams to convert words into vectors.

[0089] Step 3.2: This step yields scores for four different combinations. These four combinations are summary and program information, summary and fragment information, description and program information, and description and fragment information, with scores represented by summary_infos, summary_snps, desc_infos, and desc_snps, respectively. The specific architecture of the shallow semantic information and defect report matching module is as follows... Figure 4 As shown in the example diagram, we use the summary of the defect report and the matching of program information and fragments from the source file as examples. The word embeddings in the program information and fragment information are averaged to obtain their respective vector representations. These are vector representations of class names, method names, attribute names, and local variable names in the code, respectively. Let n be vector representations of the source file. These are vector representations of the summary and description of the defect report, respectively.

[0090] For the combination of summary and program information, we need to make the model pay more attention to the helpful program information, so we introduce an attention mechanism. We use the following formula to achieve this goal.

[0091]

[0092] in It is the integral of each piece of program information relative to the scaling point of the summary. It is a vector obtained by weighting all program information based on scaling click scores. The defect report summary encoding perceived by program information is calculated using the following equation, and finally, the fully connected layer calculates the matching score between the summary and the program information.

[0093]

[0094] For the combination of summary and fragment information, we chose TextCNN for text feature extraction. The data is fed into TextCNN, where k convolutional kernels are used to capture different n-gram features in the text. After convolution and pooling, the feature vector corresponding to each convolutional kernel is output. Finally, the feature vector corresponding to each convolutional kernel is... When concatenated, the resulting vector The vector representing a segment is the output vector after passing through TextCNN. We calculate the vector. with vector The cosine similarity is used to obtain the matching score between the summary and the fragment information.

[0095]

[0096] The calculation method for the combination of description and program information is the same as that for the combination of summary and program information, while the calculation method for the combination of description and fragment information is the same as that for the combination of summary and fragment information. Ultimately, scores are obtained for the four combinations, which are collectively referred to as shallow semantic scores (shallow_sematic).

[0097] shallow_sematic=[summary_infos;summary_snps;desc_infos;desc_snps](24)

[0098] Step 4: Construct a module for matching deep semantic information of source files with defect reports.

[0099] Step 4.1: The deep semantic information of the source file is described using natural language extracted from the source file's code. This natural language description is obtained through context-aware code translation technology. Context-aware code translation technology consists of translation rules and algorithms. Because code translation technology needs to be applied to the machine instructions of the code, these machine instructions must first be obtained. For some code, the compiler cannot obtain the entire code's instructions because necessary dependency libraries need to be introduced before compilation. However, we need to use different versions of the code in defect localization. Introducing corresponding dependency libraries for each version would complicate the process. JCoffee is a static program analysis tool. It can supplement missing classes, functions, and definitions in code snippets based on compiler error information during iteration, enabling the code snippets to compile. We first use Spoon to extract function snippets from the source file's code, and then use JCoffee to perform static analysis on these snippets. After static analysis, the compiler and decompiler are used to obtain the instruction sequence of the function snippets.

[0100] Step 4.2: The translation rules in the code translation technology are manually constructed based on the instruction specification. To strive for concise and accurate natural language translation of instructions, context-aware code translation technology manually prepares the corresponding translation for each instruction. The basic idea of ​​the translation algorithm is to simulate instruction execution by statically traversing the instruction sequence from top to bottom. Based on the specific function of each instruction, the code translation technology classifies instructions into four categories according to whether they interact with the local variable array or the operand stack. These four categories are: instructions that only interact with the operand stack, instructions that only interact with the local variable array, instructions that interact with both the operand stack and the local variable array, and instructions that do not interact with either the operand stack or the local variable array. During the traversal, the algorithm first transforms each instruction sequence into a corresponding translation result according to the translation rules. Then, it extracts the operands from each instruction; these operands are used to update the placeholders of the translation result in subsequent processes. Next, based on the above instruction classification, different processing is performed on the operands and placeholders. After traversing all instructions, the algorithm outputs the final natural language description.

[0101] Step 4.2 includes the following procedures:

[0102] Step 4.2.1: Construct translation rules:

[0103] The Java Virtual Machine Specification describes in detail how instructions interact with local variables and the operand stack. Context-aware code translation technology builds upon this by manually constructing a concise and accurate description for each instruction. For example, the instruction "istore_2" is translated as "store int[ps] into local variable[pv]", where [ps] and [pv] represent placeholders that will be filled in subsequent context traversals.

[0104] Step 4.2.2, Instruction Translation:

[0105] First, based on whether the instruction interacts with local variable arrays or operand stacks, instructions are divided into four categories: instructions that only interact with operand stacks. Instructions that interact only with arrays of local variables Instructions that interact with both the operand stack and the local variable array Instructions that do not interact with the operand stack and local variable array Classification results as follows Figure 5 As shown.

[0106] Starting from the entry point of the code, each instruction is statically traversed downwards, simulating the instruction execution process. During traversal, different contextual information is collected based on the category of each instruction. This context consists of constants, local variables, and data and control dependencies with other instructions. This context will be used to update brief descriptions of the current or other related instructions. The instruction translation process is like an algorithm. Figure 6 As shown.

[0107] Step 4.2.3: After traversing all the instructions, the transformation result of the instruction sequence is obtained. This transformation result can reflect the deep semantic information of the source code.

[0108] Step 4.3: We use the data preprocessing method described in Step 3.1 to obtain the preprocessed natural language description. In this step, two combined scores are obtained: summary and natural language description, and description and natural language description, denoted by `summary_trans` and `desc_trans`. The specific architecture of the deep semantic information and defect report matching module is as follows... Figure 7 As shown in the example diagram, this example uses the matching of the defect report summary and the natural language description of the source file. The scoring method for these two combinations is the same as that for the calculation of description and fragment information and summary and fragment information in step 2.2. Finally, the scores of the deep semantic information of the source file and the two combinations in the defect report matching module are obtained, namely the deep semantic score deep_semantic.

[0109] deep_semantic=[summary_trans;desc_trans] (25)

[0110] Step 5: Merge the results from the three matching modules.

[0111] Step 5.1: Concatenate shallow_semantic and deep_semantic, and put the concatenated result into a fully connected layer to obtain the total semantic score, semantic_score, as shown in the following formula:

[0112] semantic_score=FC([shallow_semantic; deep_semantic]) (26)

[0113] Step 5.2: Perform a final fusion of the semantic_score obtained in Step 5.1 and the wide_score obtained in Step 2.2. The final similarity score fusion_score(r,s) between the defect report r and the source file s is calculated using the following formula.

[0114] fusion_score=FC([wide_score; semantic_score]) (27)

[0115] Step 6: Defect localization can be viewed as a ranking problem. This involves calculating the similarity score between the defect report and the source file, then sorting the source files in descending order based on the score. The higher the ranking of a source file, the greater the likelihood that it contains a defect. Therefore, a hinge loss function is used to train the model. The formula for the loss function is as follows:

[0116] (r,s + ,s - ,θ)=max(0,1-fusion_score(r,s + )+fusion_score(r,s - (28)

[0117] Where θ represents all parameters in the model, s + Represents the source files associated with the defect report, s - This indicates a source file that is not related to the defect report.

Claims

1. A software defect localization method based on context-aware code translation and feature fusion, comprising the following steps: Step 1, obtaining a defect report and a source file; Step 2, constructing a traditional information retrieval and defect report matching module: Step 2.1, according to the professional knowledge in the field of software engineering, extracting the traditional information retrieval features of the defect report and the source file in step 1, the features including rVSM score, collaborative filtering score, stack trace score, cyclomatic complexity, defect repair proximate cause, defect repair frequency; Step 2.2, inputting the traditional information retrieval features obtained in step 2.1 into a fully connected network DenseNet to obtain a matching score wide_score of the source file and the defect report at the level of traditional information retrieval; characterized in that the method further comprises the following steps: Step 3, constructing a shallow semantic information and defect report matching module of the source file: Step 3.1, obtaining summary information and description information from the defect report in step 1, and obtaining program information and fragment information from the source file in step 1; Step 3.2, matching the summary information and the description information of the defect report with the program information and the fragment information of the source file two by two, and calculating four matching scores of summary-program information, summary-fragment information, description-program information and description-fragment information as shallow semantic scores shallow_semantic; Step 4, constructing a deep semantic information and defect report matching module of the source file: Step 4.1, converting the text in the source file in step 1 into an instruction sequence of code by using a compiler and a decompiler; Step 4.2, translating the instruction sequence into a natural language description by using a context-aware code translation technology, the natural language description being the deep semantic information of the source file; Step 4.3, matching the summary information and the description information of the defect report in step 3.1 with the natural language description of the source file, and calculating two matching scores of summary-instruction information and description-instruction information as deep semantic scores deep_semantic; Step 5, fusing the matching module results: Step 5.1, concatenating shallow_semantic and deep_semantic, and inputting the concatenated result into a fully connected layer to obtain a total semantic score semantic_score; Step 5.2, fusing the total semantic score semantic_score obtained in step 5.1 with the matching score wide_score obtained in step 2.2 to obtain a final similarity score between the defect report and the source file; Step 6, sorting the source files in descending order according to the final similarity score, and then recommending the sorted source file list to the developer to assist in defect localization.

2. The software defect localization method based on context-aware code translation and feature fusion according to claim 1, characterized in that, The fully connected network DenseNet comprises an input layer, N dense block bodies, N transition block bodies and an output layer, N being a positive integer, and the dense block bodies and the transition block bodies being arranged alternately.

3. The software defect localization method based on context-aware code translation and feature fusion according to claim 2, characterized in that, The input layer concatenates the traditional information retrieval features obtained in step 2.1 to obtain an input vector, and then inputs the input vector into the first dense block body: wherein r is a defect report, s is a source file, rVSMscore(r,s), cfScore(r,s), stScore(r,s), ccScore(r,s), bfrScore(r,s), bffScore(r,s) represent VSM similarity, collaborative filtering score, stack trace score, cyclomatic complexity, defect fix near cause, defect fix frequency of the defect report and the source file respectively; The output of each of the dense blocks is processed by a transition block and serves as the input of the next dense block; The output layer outputs the data processed by the last dense block and a transition block, as the matching score wide_score of the source file and the defect report in the traditional information retrieval level; wide_score=DenseNet(IR_features(r,s)) (2).

4. The software defect localization method based on context-aware code translation and feature fusion according to claim 3, characterized in that, Each of the dense blocks comprises a plurality of layers, wherein the input of the i-th layer is as follows: x i = f(x i-1 ) + x i-1 (3) where x i is the input to the i-th layer, x i-1 is the input to the i-1-th layer, f(x i-1 ) is the output of the i-1-th layer; Each layer implements a linear transformation and an activation function: f i (x i )=ReLu(FC(x i )) (4) The transition block is composed of a fully connected layer and a ReLu layer, and its formula is as follows: TransitionBlock(x)=ReLu(FC(x)) (5) wherein x is the input of the transition block.

5. The software defect localization method based on context-aware code translation and feature fusion according to claim 1, characterized in that, Step 4.2 comprises the following steps: Step 4.2.1, constructing translation rules, and then dividing the instruction sequence into four categories according to the interaction of the instruction sequence with the local variable array or the operand stack: instructions that only interact with the operand stack, instructions that only interact with the local variable array, instructions that interact with both the operand stack and the local variable array, and instructions that do not interact with both the operand stack and the local variable array; Step 4.2.2, top-down static traversal of the instruction sequence: Starting from the entry point of the code, each instruction is statically traversed step by step, simulating the execution process of the instruction; during the traversal process, each instruction is converted into the corresponding translation result according to the constructed translation rules; Step 4.2.3, during the traversal process, different context information is collected according to the category to which each instruction belongs; the context information includes constants, local variables, and data and control dependencies with other instructions; the collected context information is used to update the translation rules of the current or other related instructions; Step 4.2.4, after traversing all instructions, the conversion result generated by the instruction sequence is obtained, which is the deep semantic information of the source file.

6. The software defect localization method based on context-aware code translation and feature fusion according to claim 1, characterized in that, Step 4.3 is specifically: summary_trans is used to represent the summary-instruction information, and desc_trans is used to represent the description-instruction information; For summary_trans, choose TextCNN as the extraction of text features; For the vector representation of the n natural language description segments of the source file obtained in step 4.2, For the vector representation of the summary of the defect report; Input into TextCNN, and set k convolution kernels to capture different n-gram features in the text. After convolution and pooling, output the feature vector corresponding to each convolution kernel; finally, concatenate the feature vectors corresponding to each convolution kernel The concatenated vector represents the vector output after the vector of the segment passes through TextCNN. Calculate the cosine similarity between the vector and the vector The matching score between the summary and the segment information is obtained: The calculation method of desc_trans is the same as that of summary_trans; Finally, the deep semantic information of the source file and the scores of the two combinations in the defect report matching module are obtained, and the combination deep_semantic represents the deep semantic of the source file; deep_semantic=[summary_trans;desc_trans] (9).

7. The software defect localization method based on context-aware code translation and feature fusion according to claim 1, characterized in that, The following formula is used for splicing in step 5.1: semantic_score = FC([shallow_semantic; deep_semantic]) (10) where semantic_score is the total semantic score and FC is a fully connected layer.

8. The software defect localization method based on context-aware code translation and feature fusion of claim 1, wherein, Step 5.2 uses the following equation: fusion_score(r,s) = FC([wide_score; semantic_score]) (11) where fusion_score(r,s) is the final similarity score, r is a defect report, s is a source file, and FC is a fully connected layer.

9. The software defect localization method based on context-aware code translation and feature fusion according to claim 1, characterized in that, The model is trained in Step 6 using a hinge loss function, which has the following equation: (r,s + ,s - ,θ) = max(0, 1 - fusion_score(r,s + )+ fusion_score(r,s - )) (12) where θ are all the parameters in the model, r is a defect report, s is a source file, s + represents source files that are relevant to the defect report, s - represents source files that are not relevant to the defect report.

10. A computer-readable storage medium having stored thereon a computer program, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-9.

Citation Information

Patent Citations

  • Software defect positioning method based on similarity integration

    CN112000802A

  • Software defect positioning method based on feature crossing and structural semantic information matching

    CN117851216A