Program defect repair method and apparatus
By generating multiple code patches using various types of code repair tools, and selecting the appropriate target patch for repair, the problem of poor repair effect and low efficiency in existing technologies is solved, achieving more efficient program defect repair.
Patent Information
- Application Number
- PCT/CN2025/070470
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-07-15
- Filing Date
- 2025-01-03
- Publication Date
- 2025-12-11
AI Technical Summary
In existing program defect repair solutions, the differences between multiple candidate code patches are insufficient, resulting in poor repair effects, and attempting to repair sequentially is inefficient.
Multiple code patches are generated using various code repair tools, and the appropriate target code patch is selected for repair. Combined with static and dynamic code inspection, the selection strategy includes tool type, defect type, user requirements, etc., to ensure the diversity and applicability of the patches.
It improves the effectiveness and efficiency of program defect repair, ensuring the repair effect while reducing unnecessary repair attempts, and improving the applicability and efficiency of the repair tool.
Smart Images

Figure CN2025070470_11122025_PF_FP_ABST
Abstract
Description
A program defect repairing method and device
[0001] The present application claims priority to a Chinese patent application No. 202410725427.1, filed on June 5, 2024, entitled “A program repairing method and device”, and a Chinese patent application No. 202410946403.9, filed on July 15, 2024, entitled “A program defect repairing method and device”, both of which are incorporated herein by reference in their entirety. TECHNICAL FIELD
[0002] The present application relates to the technical field of computer, and in particular, to a program defect repairing method and device. BACKGROUND
[0003] Program defects are inevitable in software development. Program defects cause programs to fail to achieve the intended functions, and even cause programs to fail to run. Therefore, when writing a program or before the program goes online, the program is detected and the detected defects are repaired.
[0004] The current program defect repairing scheme is as follows: for the detected program defects, a series of candidate code patches are generated by using a code repairing tool; then, the candidate code patches are applied to the program one by one in a predetermined order for defect repairing; finally, the program version to which each candidate code patch is applied is tested for repairing until the program version to which a certain candidate code patch is applied passes the repairing test, and the program version is taken as the repaired program.
[0005] In this scheme, the multiple candidate code patches are generated by the same code repairing tool, which results in insufficient difference or diversity among the multiple candidate code patches. Even if the repairing of the defects by a certain candidate code patch passes the repairing test, the code patch may not be the optimal code patch, and even may bring other defects. Moreover, the scheme uses the code patches in the multiple candidate code patches for defect repairing one by one, which affects the repairing efficiency. SUMMARY
[0006] The present application provides a program defect repairing method and device, which can improve the defect repairing effect and the defect repairing efficiency.
[0007] In a first aspect, a program defect repairing method is provided. The method comprises: receiving a user-input program code; performing code inspection on the program code; when a code defect is detected in the program code, generating a plurality of code patches for the code defect using a plurality of code repairing tools, wherein each code repairing tool of the plurality of code repairing tools corresponds to a generated code patch; determining a candidate code patch for each tool type from the plurality of code patches according to a plurality of tool types to which the plurality of code repairing tools belong, wherein each code repairing tool of the plurality of code repairing tools has a tool type, and all tool types to which the plurality of code repairing tools belong have at least two types; and repairing the code defect using a target code patch, wherein the plurality of candidate code patches of the plurality of tool types include the target code patch.
[0008] The code inspection can be static code inspection, dynamic code inspection, or a combination of static and dynamic code inspection.
[0009] When a code defect is detected in the program code, the method can generate a plurality of code patches using a plurality of code repairing tools belonging to a plurality of tool types, and then determine a candidate code patch for each tool type from the plurality of code patches to obtain a plurality of candidate code patches. The plurality of candidate code patches are generated by code repairing tools of different tool types, and have rich diversity. Repairing the code defect using a target code patch from the plurality of candidate code patches of the plurality of tool types can improve the repairing effect of the code defect.
[0010] In addition, the method can directly use the target patch to repair the code defect, without sequentially attempting to use patches in the plurality of patches to repair the code defect, thereby improving the repairing efficiency of the defect.
[0011] In a possible implementation, the plurality of tool types includes at least one tool type selected by a user. The method further comprises: providing a code repairing tool interface to the user, wherein the code repairing tool interface records the code defect and a plurality of candidate tool types; and in response to a first selection operation input by the user, selecting at least one tool type from the plurality of candidate tool types.
[0012] In this implementation, the user can be provided with the code defect and the plurality of candidate tool types, so that the user can select a tool type for the code defect, and then use a code patch generated by a code repairing tool of the selected tool type to repair the code defect.
[0013] In a possible implementation, the at least two tool types in the plurality of tool types are selected by using at least two selection strategies, each of the at least two selection strategies is used to select at least one tool type in the at least two tools, the at least two selection strategies include at least two of a first selection strategy, a second selection strategy, and a third selection strategy, the first selection strategy is used to select a tool type with patch generation capability, the second selection strategy is used to select a tool type based on historical repair information corresponding to a defect type, and the third selection strategy is used to select a tool type based on requirement information of a user, the patch generation capability is patch generation capability required by a code defect, and the defect type is a type to which the code defect belongs.
[0014] The method selects a tool type for the code defect by using the at least two selection strategies, so that a tool type with rich diversity can be selected. In this way, a code patch with rich diversity can be generated by using a code repair tool with rich diversity, so that the repair effect can be further improved.
[0015] In a possible implementation, the at least two code repair tools in the plurality of code repair tools belong to a same tool type, and determining, according to the plurality of tool types to which the plurality of code repair tools belong, one candidate code patch for each tool type from the plurality of code patches includes: using a first code patch or a second code patch in the at least two code patches generated by the at least two code repair tools as a candidate code patch of a tool type to which the at least two code repair tools belong, the first code patch is one code patch in at least one code patch in the at least two code patches whose opinion convergence degree is greater than a first threshold, and the opinion convergence degree of the first code patch is positively correlated with a number of code patches in the at least two code patches that have a similarity greater than a second threshold with the first code patch, and the second code patch is one code patch in at least one code patch in the at least two code patches that can repair the code defect.
[0016] The opinion convergence degree of the first code patch is greater than the first threshold, which means that there are more code patches with high similarity to the first patch, and the first code patch is probably a patch suitable for the code defect. The second code patch can repair the code defect, which means that the second code patch is also a patch suitable for the code defect.
[0017] In this implementation, the at least two code repair tools under the same tool type generate at least two code patches for the code defect, and then a patch suitable for the code defect in the at least two code patches is used as a candidate code patch of the tool type. In this way, the patches in the plurality of candidate code patches are all patches suitable for the code defect, so that the target code patch is also a patch suitable for the code defect.
[0018] In a possible implementation, the method comprises: providing a code patch interface to the user, the code patch interface recording at least two candidate code patches in the plurality of candidate code patches; and selecting a target code patch from the at least two candidate code patches in response to a second selection operation input by the user.
[0019] The implementation enables the user to see the at least two candidate code patches by providing the code patch interface to the user, so that the user can select the target code patch from the at least two candidate code patches.
[0020] In a possible implementation, the code patch interface further records a repair explanation of each of the at least two code patches.
[0021] In the implementation, the user can also see the repair explanation of the code patch through the code patch interface, so as to facilitate the user to select the target code patch according to the repair explanation.
[0022] In a possible implementation, the code repair tool that generates the code patch also generates a first repair explanation of the code patch, and the code patch interface provided to the user comprises: inputting each of the plurality of candidate code patches into the large language model, so that the large language model outputs a second repair explanation of the candidate code patch; and selecting the at least two candidate code patches from the plurality of candidate code patches based on a similarity between the second repair explanation of each of the plurality of candidate code patches and the first repair explanation of the candidate code patch.
[0023] In the implementation, the code patch with a more correct repair explanation is displayed to the user through the code patch interface, so that the user can select the target code patch based on the correct repair explanation.
[0024] In a second aspect, a program defect repair apparatus is provided, which comprises: a receiving module configured to receive program code input by a user; an inspection module configured to perform code inspection on the program code; a generating module configured to, when it is found that the program code has code defects, generate a plurality of code patches for the code defects by using a plurality of code repair tools, wherein each of the plurality of code repair tools corresponds to a generated code patch; a determining module configured to, according to a plurality of tool types to which the plurality of code repair tools belong, determine one candidate code patch for each tool type from the plurality of code patches, wherein each of the plurality of code repair tools has one tool type, and all tool types to which the plurality of code repair tools belong have at least two tool types; and a repairing module configured to repair the code defects by using a target code patch, wherein the plurality of candidate code patches of the plurality of tool types include the target code patch.
[0025] In a possible implementation, the plurality of tool types includes at least one tool type selected by the user, and the generating module is configured to: provide a code repair tool interface to the user, the code repair tool interface recording the code defect and the plurality of candidate tool types; and in response to a first selection operation input by the user, select at least one tool type from the plurality of candidate tool types.
[0026] In a possible implementation, at least two tool types in the plurality of tool types are selected by using at least two selection strategies, where each of the at least two selection strategies is used to select at least one tool type from the at least two tools; the at least two selection strategies include at least two of a first selection strategy, a second selection strategy, and a third selection strategy; the first selection strategy is used to select a tool type having patch generation capability, the second selection strategy is used to select a tool type based on historical repair information corresponding to a defect type, and the third selection strategy is used to select a tool type based on requirement information of the user; the patch generation capability is a patch generation capability required by the code defect, and the defect type is a type to which the code defect belongs.
[0027] In a possible implementation, at least two code repair tools in the plurality of code repair tools belong to the same tool type; and the determining module is configured to: use a first code patch or a second code patch from at least two code patches generated by the at least two code repair tools as a candidate code patch of a tool type to which the at least two code repair tools belong; the first code patch is one of at least one code patch in the at least two code patches whose opinion convergence degree is greater than a first threshold value, and the opinion convergence degree of the first code patch is positively correlated with a number of code patches in the at least two code patches that have a similarity greater than a second threshold value with the first code patch; and the second code patch is one of at least one code patch in the at least two code patches that can repair the code defect.
[0028] In a possible implementation, the repairing module is configured to: provide a code patch interface to the user, the code patch interface recording at least two candidate code patches from the plurality of candidate code patches; and in response to a second selection operation input by the user, select a target code patch from the at least two candidate code patches.
[0029] In a possible implementation, the code patch interface further records a repair explanation of each code patch in the at least two code patches.
[0030] In a possible implementation, the code repair tool that generates the code patch also generates a first repair explanation of the code patch, and the repair module is configured to: input each candidate code patch in the plurality of candidate code patches into the large language model, so that the large language model outputs a second repair explanation of the candidate code patch; and select at least two candidate code patches from the plurality of candidate code patches based on a similarity between the second repair explanation of each candidate code patch in the plurality of candidate code patches and the first repair explanation of the candidate code patch.
[0031] In a third aspect, a computing device cluster is provided, including at least one computing device, each computing device including a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method provided in the first aspect.
[0032] In a fourth aspect, a computer-readable storage medium is provided, including computer program instructions, when the computer program instructions are executed by a computing device cluster, the computing device cluster executes the method provided in the first aspect.
[0033] In a fifth aspect, a computer program product including instructions is provided, when the instructions are executed by a computing device cluster, the computing device cluster executes the method provided in the first aspect.
[0034] The beneficial effects of the second aspect to the fifth aspect can refer to the beneficial effects of the first aspect described above, and will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS
[0035] FIG. 1 is a schematic diagram of a system architecture provided by an embodiment of the present application;
[0036] FIG. 2 is a flowchart of a program defect repair method provided by an embodiment of the present application;
[0037] FIG. 3 is a schematic diagram of a code repair tool interface provided by an embodiment of the present application;
[0038] FIG. 4 is a schematic diagram of a code repair tool classification provided by an embodiment of the present application;
[0039] FIG. 5 is a schematic diagram of a patch generation provided by an embodiment of the present application;
[0040] FIG. 6 is a schematic diagram of a patch generation provided by an embodiment of the present application;
[0041] FIG. 7 is a schematic diagram of a code patch interface provided by an embodiment of the present application;
[0042] FIG. 8 is a schematic diagram of a patch evaluation provided by an embodiment of the present application;
[0043] FIG. 9 is a structural schematic diagram of a program defect repairing device according to an embodiment of the present application;
[0044] FIG. 10 is a structural schematic diagram of a computing device according to an embodiment of the present application;
[0045] FIG. 11 is a structural schematic diagram of a computing device cluster according to an embodiment of the present application;
[0046] FIG. 12 is a structural schematic diagram of a computing device cluster according to an embodiment of the present application. DETAILED DESCRIPTION
[0047] The schemes provided by the embodiments of the present application will be described below with reference to the accompanying drawings. In the embodiments of the present application, "multiple" refers to two or more, and "multiple types" refers to two or more types. "First", "second", and the like are only used to distinguish similar objects, and do not necessarily indicate a specific order or number of objects.
[0048] To facilitate understanding of the schemes provided by the embodiments of the present application, the technical terms that may be involved in the embodiments of the present application will be introduced first.
[0049] Code defect: which can be referred to as defect, vulnerability or bug, refers to an error existing in program code. These errors can cause the program function to fail to execute normally, the computer system running the program to crash, data loss or unintended interruption, and other adverse consequences. Generally, program defects involve errors of one or more functions in the program, including errors in the implementation of the function, errors in the function call, and other logic errors related to the function.
[0050] Dynamic and static defect positioning technology: is a defect detection technology that locates code defects in a program through dynamic test execution methods and static program analysis methods. The dynamic test execution method is to sort the error positions of the program according to the dynamic runtime characteristics of the program that does not pass the test and passes the test. The positioning method based on program spectrum is a specific dynamic test execution method. The static program analysis method is to describe the specification of the program through pre-defined rules, and then determine whether the program meets the given rules through program analysis technology.
[0051] Code patch: is a computer code used to repair program defects.
[0052] Code repair tool: is a tool that generates code patches and repair explanations based on a set patch generation algorithm. Common code repair tools include code check, AI-1, AI-2, AI-3, bugzoo, sec, ARJA, ACS, DSL, copilot, etc. In the following description, the code repair tool can be referred to as tool.
[0053] Repair explanation: refers to the logic for explaining that the generated code patch repairs the code defect. For example, the repair explanation can be "call parameter error, this code patch is used to modify the call parameter", etc. The higher the accuracy of the repair explanation, the higher the success rate of the code patch corresponding to the repair explanation in repairing the code defect.
[0054] Tool type: refers to the type of code repair tool. According to the repair type of the code repair tool, the tool type can be divided, for example, the tool type supporting security class repair, the tool type supporting style class repair, the tool type supporting coding specification class repair, and the tool type supporting code logic class repair. According to whether the code repair tool supports compilation, the code repair tool can be divided into tool types that support compilation and repair types that do not support compilation. According to the underlying technology adopted by the code repair tool, the tool type can be divided, for example, the tool type based on flow control, the tool type based on machine learning, the tool type based on syntax tree, and the tool type based on symbolic execution. In addition, the tool type can be divided according to the patch generation strategy integrated or adopted by the code repair tool. For example, some patch generation strategies are to generate a code patch that can replace the code segment where the defect is located, and in the repair, the code patch directly replaces the code segment where the defect is located. For another example, some patch generation strategies are to generate a code patch that can modify the corresponding parameters at the defect location, and in the repair, the code patch modifies the corresponding parameters at the defect location to repair the defect. And so on, which will not be listed one by one here.
[0055] The code patches generated by code repair tools of different tool types have advantages and disadvantages, and may be suitable for different types of code defects. The current program defect repair scheme, when checking that the program code has a code defect, uses the same code repair tool to generate multiple code patches, and then tries whether the code patch in the multiple code patches can repair the code defect to complete the code defect repair. Although this scheme may eventually achieve code defect repair, the generation strategy corresponding to the code repair tool may not be suitable for the code defect, so that the patch may not be suitable for the code defect, resulting in poor repair effect, such as large difference between the code patch and the program code style, introduction of sensitive functions in the program, etc.
[0056] The embodiment of the present application provides a program defect repairing method, which is used for generating a plurality of code patches by using a plurality of code repairing tools of different tool types, and repairing a defect by using a target code patch in the plurality of code patches, so as to improve the repairing effect. Specifically, the method can perform code checking on program code input by a user; when it is checked that the program code has a code defect, a plurality of code repairing tools respectively belonging to different tool types are used to generate a plurality of code patches for the code defect, wherein each code repairing tool in the plurality of code repairing tools corresponds to a code patch; then, a candidate code patch for each tool type is determined from the plurality of code patches according to a plurality of tool types to which the plurality of code repairing tools belong, so that a plurality of candidate code patches of the plurality of tool types are obtained; and finally, a target code patch is selected from the plurality of candidate code patches, and the target code patch is used to repair the code defect.
[0057] Different candidate code patches in the plurality of candidate code patches are of different tool types, and the diversity is rich, so that a code patch suitable for the code defect, i.e., the target code patch, can be selected from the plurality of candidate code patches. The code defect can be repaired by using the target code patch, so as to ensure the repairing effect of the code defect.
[0058] Next, the program defect repairing method provided by the embodiment of the present application is described in detail.
[0059] FIG. 1 shows a system architecture that can be used to implement the method. The system architecture includes a device 100 and a device 200. The device 100 or the device 200 can be any device, equipment, cluster or platform having a data processing function. The device 100 can be deployed locally to a user, and the device 200 can be deployed in the cloud.
[0060] The device 100 can be used to write or run program code by a user, and display related interfaces, such as a code repairing tool interface, a code patch interface and the like described below.
[0061] The device 200 is used to execute the program defect repairing method provided by the embodiment of the present application. As shown in FIG. 1, the device 200 can include a receiving module, a checking module, a generating module, a determining module and a repairing module. The device 200 can execute the method through these modules.
[0062] The receiving module can receive a program code input by a user through the device 100. The checking module can perform code checking on the program code to find code defects of the program code. The generating module is configured to generate a plurality of code patches for the found code defects by using a plurality of code repair tools belonging to different tool types. The determining module is configured to determine candidate code patches of each tool type in the plurality of code patches, wherein one tool type corresponds to one candidate code patch. The repairing module is configured to select a target code patch from the candidate code patches of the plurality of tool types, and repair the code defects by using the target code patch.
[0063] Next, the program defect method provided by the embodiment of the present application will be described in detail in combination with the flow chart shown in FIG. 2.
[0064] In step 201, a user can input a program code in the device 100 through an input operation.
[0065] In some embodiments, the input operation can be a program writing operation for writing a program in the device 100. In some embodiments, the input operation can be a program code input operation for inputting a complete executable program code in the device 100. In some embodiments, the input operation can instruct the device 200 to start the defect detection capability to detect the program code periodically or when a preset condition is triggered (for example, when the enter key is struck) to find whether the program code has code defects.
[0066] In step 202, the device 200 can receive the program code input by the user from the device 100. After the device 100 receives the program code input by the user, the device 100 can send the program code to the device 200. For example, the device 200 can affect the input operation of the user, start the defect detection capability, and periodically or when a preset condition is triggered, obtain the program code recently input by the user from the device 100.
[0067] In step 203, after receiving the program code, the device 200 can perform code checking on the program code.
[0068] In some embodiments, the device 200 can perform checking on the program code by using a static code checking technology to find code defects. In some embodiments, the device 200 can perform checking on the program code by using a dynamic code checking technology to find code defects. In some embodiments, the code defects can be checked by using a dynamic and static defect positioning technology to find code defects. The dynamic and static defect positioning technology mainly finds code defects and specific positions or ranges of the code defects in the program code by using static analysis and dynamic testing and other technical means.
[0069] At step 204, the device 200 generates a plurality of code patches for the code defects respectively by using a plurality of code repair tools when the code defects are detected in the program code. The plurality of code repair tools can belong to a plurality of tool types, that is, the plurality of code repair tools include at least one code repair tool under each tool type in the plurality of tool types.
[0070] In some embodiments, at least one tool type in the plurality of tool types can be selected by a user. As shown in FIG. 2, when the code defects are detected in the program code, the device 200 can provide a code modification tool interface to the user through step 2041. In step 2041, the device 200 sends the code repair tool interface to the device 100, so that the device 100 displays the code repair tool interface to the user. As shown in FIG. 3, the code repair tool interface records the discovered code defects and a plurality of candidate tool types, such as tool type B1, tool type B2, tool type B3, etc. The user can input a selection operation C1 through step 2042. The selection operation C1 indicates the tool type selected by the user from the plurality of candidate tool types. The device 100 can receive the selection operation C1 input by the user and send the selection operation C1 to the device 200 through step 2043. The device 200 can confirm the tool type selected by the user from the plurality of candidate tool types in response to the selection operation C1, that is, select the at least one tool type from the plurality of candidate tool types.
[0071] In some embodiments, at least two tool types in the plurality of tool types are selected by the device 200 using at least two selection strategies, wherein each selection strategy is used to select at least one of the at least two tools. The device 200 can select one or more tool types by using each selection strategy, and then take the union of the tool types selected by using the plurality of selection strategies to obtain the at least two tool types.
[0072] In some embodiments, the device 200 can obtain defect information of the code defects, and then select at least two tool types for the code defects based on the defect information of the code defects by using the at least two selection strategies.
[0073] The defect information of the code defect refers to information related to the code defect. In some embodiments, the defect information can include a defect type of the code defect, a patch generation capability required for code defect repair, a code segment where the code defect is located, a code segment having a calling relationship with the code segment where the code defect is located, a location of the code defect, and the like. Among them, the code segment where the code defect is located can be a function where the code defect is located. The code segment having a calling relationship with the code segment where the code defect is located can be a function having a calling relationship with the function where the code defect is located. In some embodiments, the defect information can include user demand information. Among them, the user demand information is information indicating a defect repair demand of a development user or a maintenance user of the program code, for example, the user demand information can be "inter-function calling uses API". For example, after discovering the code defect, the user can be prompted about the code defect. The user can input the demand information for the code defect. In some embodiments, the defect information can be recorded in the form of defect tuple information.
[0074] Among them, the patch generation capability required for code defect repair can also be referred to as the patch generation capability required for code defect repair, which refers to the capability required for generating a patch capable of repairing the code defect. For example, the code segment where the code defect is located is a security class code, and accordingly, the code defect belongs to a security class defect, then the patch generation capability required for code defect repair includes the capability of generating a patch capable of repairing the security class defect. For another example, the code defect is a logic class defect, then the generation of the patch depends on the compilation, and then the patch generation capability required for code defect repair includes support for compilation. For another example, the code segment where the code defect is located is a control flow based code, and accordingly, the patch should also be a control flow based code, then the patch generation capability required for code defect repair includes the capability of generating a control flow based patch. And so on, which will not be listed one by one here.
[0075] In some embodiments, as shown in FIG. 4, the patch generation capability required for code defect repair can be divided into repair types, repair demands, underlying technologies required for repair, and the like. Among them, the repair types can be divided into security class repair, style class repair, coding specification class repair, and code logic class repair. Among them, the repair demands can be divided into support for compilation and no support for compilation. The underlying technology can be divided into control flow based, machine learning based, syntax tree based, and symbol execution based, and the like.
[0076] In some embodiments, the patch generation capability required for code defect repair can be obtained through defect detection technology, for example, the dynamic and static defect positioning technology can analyze the patch generation capability required for code defect repair when discovering the code defect.
[0077] In some embodiments, the patch generation capability required by the code defect repair can be obtained by analyzing the code segment where the code defect is located. For example, the code type to which the code segment where the code defect is located belongs can be analyzed. If the code segment where the code defect is located belongs to a security type code, it can be determined that the code defect belongs to a security type defect, and then it can be confirmed that the patch generation capability required by the code defect includes the capability of generating a patch capable of repairing a security type defect. For another example, if the code defect is found in the code running process, it means that the code defect is a logic type defect, and then the patch generation capability required by the code defect includes the compiling capability. For another example, whether the code segment where the code defect is located is a control flow code can be analyzed. If yes, the patch generation capability required by the code defect repair includes the capability of generating a patch based on the control flow. And so on, which will not be listed here one by one.
[0078] The identification manner of the style type repair, the coding specification type repair or the code logic type repair can be implemented by referring to the identification manner of the security type code described above. The identification manners based on machine learning, based on syntax tree and based on symbolic execution can be implemented by referring to the identification manner based on the control flow.
[0079] In some embodiments, the defect information of the code defect includes the patch generation capability required by the code defect repair and the defect type, and the plurality of selection strategies include: a selection strategy A1 for selecting a tool type with the patch generation capability and a selection strategy A2 for selecting a tool type based on the historical repair information corresponding to the defect type.
[0080] In some embodiments, the defect information of the code defect includes the patch generation capability required by the code defect repair and the user demand information, and the plurality of selection strategies include: the selection strategy A1 and a selection strategy A3 for selecting a tool type based on the user demand information.
[0081] In some embodiments, the defect information of the code defect includes the defect type and the user demand information, and the plurality of selection strategies include: the selection strategy A2 and the selection strategy A3.
[0082] In some embodiments, the defect information of the code defect includes the patch generation capability required by the code defect repair, the defect type and the user demand information, and the plurality of selection strategies include: the selection strategy A1, the selection strategy A2 and the selection strategy A3.
[0083] Different tool types can support different patch generation capabilities. For example, as shown in FIG. 4, the tool type B1 supports the style type repair, supports the compiling, supports the machine learning, etc. The tool type B2 supports the style type repair, does not support the compiling, supports the control flow based. The tool type B3 supports the security type repair, supports the compiling, supports the syntax tree based. And so on, which will not be listed here one by one.
[0084] Based on the patch generation capability required by the code defect repair in the defect information, the selection strategy A1 can be used to select at least one tool type for the code defect. For example, the patch generation capability required by the code defect repair is: supporting coding specification repair, supporting compilation, and supporting machine learning, and then the tool type selected by the selection strategy A1 is the tool type B1.
[0085] The historical repair information corresponding to the defect type records the tool type used to repair the defect under the defect type in history and the repair result. The repair result can be a successful repair result or a failed repair result. In step 204, based on the defect type in the defect information, the historical repair information corresponding to the defect type can be obtained in the historical repair information library. Then, based on the historical repair information corresponding to the defect type, the selection strategy A2 is used to select the tool type for the code defect. Specifically, if the repair result recorded in the historical repair information is a successful repair result, the tool type recorded in the historical repair information (i.e., the tool type used to repair the defect under the defect type in history) is selected as the tool type for repairing the code defect. If the repair result recorded in the historical repair information is a failed repair result, a tool type other than the tool type recorded in the historical repair information is selected as the tool type for repairing the code defect.
[0086] The user demand information indicates the tool type that the user wants to use. For example, the user demand information is "function call using API", and the tool type that the user wants to use is the tool type that can generate a patch with API as the function call mode. In step 204, based on the user demand information in the defect information, the tool type that the user wants to use can be identified. Then, based on the selection strategy A3, the tool type that the user wants to use or a tool type similar to the tool type that the user wants to use is selected.
[0087] In this way, by the above-mentioned manner, multiple tool types can be selected for the code defect.
[0088] There is one or more code repair tools under each tool type, and each code repair tool under each tool type can be used to generate a code patch for the code defect. One code repair tool generates one code patch, and multiple code repair tools under multiple tool types can generate multiple code patches.
[0089] In step 205, the apparatus 200 determines a candidate code patch for each tool type from the multiple code patches according to the multiple tool types to which the multiple code repair tools belong.
[0090] A tool type can have at least two code repair tools. For example, as shown in FIG. 4, under tool type B1, there are tool B11 (which can be specifically code check), tool B12 (which can be specifically AI-1), tool B13 (which can be specifically sec), etc., under tool type B2, there are tool B21 (which can be specifically AI-2), tool B22 (which can be specifically ARJA), tool B23 (which can be specifically bugzoo), etc., under tool type B3, there are tool B31 (which can be specifically AI-3), tool B32 (which can be specifically ACS), tool B33 (which can be specifically DSL), etc.
[0091] Each of the at least two code repair tools under the same tool type can generate a code patch for the code defect, resulting in at least two patches. Then, one code patch is selected from the at least two code patches as a candidate code patch of the tool type. For example, as shown in FIG. 5, the multiple code repair tools used in step 204 can belong to tool type B1 and tool type B2, and each of the code repair tools under tool type B1 and tool type B2 generates a code patch for the code defect. Specifically, tool B11 generates code patch b11, tool B12 generates code patch b12, tool B13 generates code patch b13, tool B21 generates code patch b21, tool B22 generates code patch b22, and tool B23 generates code patch b23. Among them, the candidate code patch b1 of tool type B1 is selected from code patch b11, code patch b12 and code patch b13, and the candidate code patch b2 of tool type B2 is selected from code patch b21, code patch b22 and code patch b23.
[0092] In some embodiments, one of the at least two code patches generated by the at least two code repair tools under the same tool type, which passes the repair verification, can be selected as the candidate code patch of the tool type. For example, one of the code patch b11, the code patch b12, and the code patch b13, which passes the repair verification, can be selected as the candidate code patch b1 of the tool type B1. Specifically, the target patch can be repaired using the patch b11, and it is determined whether the repair result passes the repair verification. If the repair result passes the repair verification, the code patch b11 is selected as the candidate code patch b1. If the repair result does not pass the repair verification, the target patch is repaired using the code patch b12, and it is determined whether the repair result passes the repair verification. If the repair passes the repair verification, the code patch b11 is selected as the candidate code patch b1. In this way, the candidate code patch b1 is selected. For another example, one of the code patch b21, the code patch b22, and the code patch b23, which passes the repair verification, can be selected as the candidate code patch b2. The candidate code patch b2 of the tool type B1 can also be selected in the foregoing manner. That is, one of the at least two code patches under the same tool type, which can repair the code defect, is used as the candidate code patch of the tool type.
[0093] In some embodiments, one of the at least two code patches generated by the at least two code repair tools under the same tool type, which has an opinion consistency degree greater than a threshold Y1, can be selected as the candidate code patch of the tool type. The opinion consistency degree of the code patch refers to the proportion of the code patches consistent with the code patch in the at least two code patches. That is, the proportion of the code patches consistent with the candidate code patch in the at least two code patches is greater than the threshold Y1. The threshold Y1 can be a preset value, for example, 50% or 60%, etc. For example, the consistency of the code patches refers to the similarity between the code patches being greater than a threshold Y2. That is, the opinion consistency degree of the code patch is positively correlated with the number of the code patches in the at least two code patches, which have a similarity greater than the threshold Y2 with the code patch. The threshold Y2 can be a preset value, for example, 70% or 80%, etc. For example, the similarity between the code patches can be semantic similarity. For example, the similarity between the code patches can be code similarity.
[0094] In one example of this embodiment, as shown in FIG. 6, the opinion consistency degree of each of the at least two code patches generated by the at least two code repair tools under the same tool type can be calculated, and it is determined whether there is a code patch with an opinion consistency degree greater than a threshold Y1 in the at least two code patches. If there is, the code patch with the opinion consistency degree greater than the threshold Y1 is output as the candidate code patch. If there is not, the code repair tool under the tool type is instructed to regenerate the code patch.
[0095] In this way, the candidate code patch of each tool type can be obtained through the above manner.
[0096] Continuing to refer to FIG. 2, at step 206, the apparatus 200 repairs the code defect by using a target code patch, and the plurality of candidate code patches of the plurality of tool types includes the target code patch.
[0097] In some embodiments, the apparatus 200 can provide a code patch interface to the user. As shown in FIG. 7, the code patch interface records at least two candidate code patches in the plurality of candidate code patches of the plurality of tool types, such as candidate code patch b1, candidate code patch b2, and the like. In one example, the code patch interface further records a repair explanation of each code patch in the at least two candidate code patches. The repair explanation is used to explain the logic of the generated code patch to repair the code defect. For example, the repair explanation can be “call parameter error, this code patch is used to modify the call parameter”, and the like. The higher the accuracy of the repair explanation, the higher the success rate of the code patch corresponding to the repair explanation to repair the code defect.
[0098] The apparatus 200 can send the code patch interface to the apparatus 100 through step 2061, so that the apparatus 100 can display the code patch interface to the user. The user can input a selection operation C2 at step 2062, and the selection operation C2 is used to indicate the target code patch in the at least two candidate code patches. The apparatus 200 can receive the selection operation C2 input by the user from the apparatus 100 through step 2063, and select the target code patch from the at least two candidate code patches in response to the selection operation C2.
[0099] In some embodiments, the apparatus 200 can evaluate each candidate code patch in the plurality of candidate code patches to obtain a score. The at least two candidate code patches are candidate code patches in the plurality of candidate code patches whose scores are greater than a preset threshold, or the at least two candidate code patches are at least two candidate code patches in the plurality of candidate code patches with the largest scores.
[0100] In one example of this embodiment, the code fix tool that generates the code patch also generates a fix explanation of the code patch. Each of the plurality of candidate code patches has a fix explanation D1 generated by the code fix tool. Each of the plurality of candidate code patches can be input to a large language model (LLM) such that the LLM outputs a fix explanation D2 of the patch. Then, based on a similarity between the fix explanation D1 of each of the plurality of candidate code patches and the fix explanation D2 of the candidate code patch, the at least two candidate code patches are selected from the plurality of candidate code patches. The similarity between the fix explanation D1 of the candidate code patch and the fix explanation D2 of the candidate code patch is positively correlated with a score of the candidate code patch. The score of the candidate code patch is obtained by the similarity between the fix explanation D1 of the candidate code patch and the fix explanation D2 of the candidate code patch.
[0101] For example, as shown in FIG. 8, the code patch and the fix explanation of the code patch generated by the code fix tool can be spliced, and the spliced result can be input to a large language model. The large language model can compare each code patch and the fix explanation of the code patch to obtain a comparison matrix. The comparison between the patch and the fix explanation of the code patch can be that the large language model understands the code patch and generates the fix explanation of the code patch based on the understanding result. Then, the generated fix explanation and the input fix explanation are compared to obtain a comparison matrix. The large language model normalizes the comparison matrix to obtain and output scores of the plurality of code patches.
[0102] In summary, the program defect repair method provided in the embodiments of the present application can generate a plurality of code patches by using a plurality of code fix tools belonging to a plurality of tool types when detecting that the program code has a code defect. Then, candidate code patches of each tool type are determined from the plurality of code patches to obtain a plurality of candidate code patches. The plurality of candidate code patches are generated by code fix tools of different tool types and have rich diversity. The target code patch in the plurality of candidate code patches of the plurality of tool types can be used to repair the code defect, which can improve the repair effect of the code defect. Moreover, the target code patch can be directly used to repair the code defect without sequentially trying a plurality of code patches to repair the defect, which improves the repair efficiency of the code defect.
[0103] The embodiments of the present application also provide a program defect repair device 900, as shown in FIG. 9, the device 900 comprises:
[0104] The receiving module 910 is configured to receive the program code input by a user.
[0105] The checking module 920 is configured to perform code checking on the program code.
[0106] The generating module 930 is configured to generate a plurality of code patches for the code defects respectively by using a plurality of code repair tools when it is detected that the program code has code defects, wherein each of the plurality of code repair tools corresponds to generate one code patch;
[0107] The determining module 940 is configured to determine a candidate code patch for each tool type from the plurality of code patches according to a plurality of tool types to which the plurality of code repair tools belong, wherein each of the plurality of code repair tools has one tool type, and all tool types to which the plurality of code repair tools belong have at least two tool types;
[0108] The repairing module 950 is configured to repair the code defects by using a target code patch, and the plurality of candidate code patches of the plurality of tool types include the target code patch.
[0109] In some embodiments, the plurality of tool types includes at least one tool type selected by the user, and the generating module 930 is configured to: provide a code repair tool interface to the user, the code repair tool interface recording the code defects and a plurality of candidate tool types; and select the at least one tool type from the plurality of candidate tool types in response to a first selection operation input by the user.
[0110] In some embodiments, at least two tool types in the plurality of tool types are selected by using at least two selection strategies, wherein each of the at least two selection strategies is used to select at least one tool type in the at least two tools; the at least two selection strategies include at least two of a first selection strategy, a second selection strategy, and a third selection strategy; wherein the first selection strategy is used to select a tool type having a patch generation capability, the second selection strategy is used to select a tool type based on historical repair information corresponding to a defect type, and the third selection strategy is used to select a tool type based on demand information of the user; the patch generation capability is a patch generation capability required by the code defects, and the defect type is a type to which the code defects belong.
[0111] In some embodiments, the at least two code repair tools among the plurality of code repair tools belong to a same tool type; the determining module 940 is configured to: use a first code patch or a second code patch among at least two code patches generated by the at least two code repair tools as a candidate code patch of the tool type to which the at least two code repair tools belong; the first code patch is one of at least one code patch among the at least two code patches whose opinion convergence degree is greater than a first threshold value, and the opinion convergence degree of the first code patch is positively correlated with a number of code patches among the at least two code patches that have a similarity greater than a second threshold value with the first code patch; the second code patch is one of at least one code patch among the at least two code patches that can repair the code defect.
[0112] In some embodiments, the repairing module 950 is configured to: provide a code patch interface to the user, the code patch interface recording at least two candidate code patches among the plurality of candidate code patches; and select the target code patch from the at least two candidate code patches in response to a second selection operation input by the user.
[0113] In one example of this embodiment, the code patch interface further records a first repair explanation of each code patch among the at least two code patches.
[0114] In another example of this embodiment, the code repair tool that generates the code patch also generates a first repair explanation of the code patch, and the repairing module 950 is configured to: input each candidate code patch among the plurality of candidate code patches into a large language model, so that the large language model outputs a second repair explanation of the candidate code patch; and select the at least two candidate code patches among the plurality of candidate code patches based on a similarity between the second repair explanation of each candidate code patch among the plurality of candidate code patches and the first repair explanation of the candidate code patch.
[0115] The receiving module 910, the checking module 920, the generating module 930, the determining module 940, and the repairing module 950 can be implemented by software or by hardware. For example, the implementation of the receiving module 910 is described below. Similarly, the implementation of the checking module 920, the generating module 930, the determining module 940, and the repairing module 950 can be implemented by referring to the implementation of the receiving module 910.
[0116] As an example of a software functional unit, the receiving module 910 can include code running on a compute instance. The compute instance can include at least one of a physical host (computing device), a virtual machine, a container. Further, the compute instance can be one or more. For example, the receiving module 910 can include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers for running the code can be distributed in the same region, or in different regions. Further, the multiple hosts / virtual machines / containers for running the code can be distributed in the same availability zone (AZ), or in different AZs, each of which includes one data center or multiple data centers in close geographical proximity. Generally, one region can include multiple AZs.
[0117] Similarly, the multiple hosts / virtual machines / containers for running the code can be distributed in the same virtual private cloud (VPC), or in multiple VPCs. Generally, one VPC is set up in one region, and communication between two VPCs in the same region, or between VPCs in different regions, needs to be set up in each VPC to set up a communication gateway, and the interconnection between VPCs is realized through the communication gateway.
[0118] As an example of a hardware functional unit, the receiving module 910 can include at least one computing device, such as a server, etc. Alternatively, the receiving module 910 can also be a device implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD), etc. The PLD can be implemented by a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0119] The multiple computing devices included in the receiving module 910 can be distributed in the same region or in different regions. The multiple computing devices included in the receiving module 910 can be distributed in the same AZ or in different AZs. Likewise, the multiple computing devices included in the receiving module 910 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0120] It should be noted that, in other embodiments, the receiving module 910 can be configured to perform any of the steps performed by the apparatus 200 in the method shown in FIG. 2, the checking module 920 can be configured to perform any of the steps performed by the apparatus 200 in the method shown in FIG. 2, the generating module 930 can be configured to perform any of the steps performed by the apparatus 200 in the method shown in FIG. 2, the determining module 940 can be configured to perform any of the steps performed by the apparatus 200 in the method shown in FIG. 2, and the repairing module 950 can be configured to perform any of the steps performed by the apparatus 200 in the method shown in FIG. 2. The steps implemented by the receiving module 910, the checking module 920, the generating module 930, the determining module 940, and the repairing module 950 can be specified as needed, and the overall functions of the apparatus 900 can be implemented by the receiving module 910, the checking module 920, the generating module 930, the determining module 940, and the repairing module 950 respectively implementing different steps in the steps performed by the apparatus 200 in the method shown in FIG. 2.
[0121] The present application also provides a computing device 1000. As shown in FIG. 10, the computing device 1000 includes a bus 1002, a processor 1004, a memory 1006, and a communication interface 1008. The processor 1004, the memory 1006, and the communication interface 1008 communicate through the bus 1002. The computing device 1000 can be a server or a terminal device. It should be understood that the number of processors and memories in the computing device 1000 is not limited by the present application.
[0122] The bus 1002 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one line is shown in FIG. 10, but it does not mean that there is only one bus or only one type of bus. The bus 1002 can include a path for transmitting information between various components (e.g., the memory 1006, the processor 1004, the communication interface 1008) of the computing device 1000.
[0123] The processor 1004 can include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP), among other processors.
[0124] The memory 1006 can include volatile memory (e.g., random access memory (RAM)), non-volatile memory (e.g., read-only memory (ROM)), flash memory, a hard disk drive (HDD), or a solid-state drive (SSD), among others.
[0125] The memory 1006 stores executable program code that the processor 1004 executes to implement the functionality of the aforementioned receiving module 910, checking module 920, generating module 930, determining module 940, and repairing module 950, respectively, and thus implement the steps performed by the apparatus 200 in the method of FIG. 2. That is, the memory 1006 has instructions stored thereon for performing the steps performed by the apparatus 200 in the method of FIG. 2.
[0126] The communication interface 1008 enables communication among the computing device 1000 and other devices or communication networks using, for example and without limitation, a transceiver, a network interface card, a modem, or other type of interface.
[0127] Embodiments of the present disclosure also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device, such as a desktop computer, a laptop computer, or a smartphone.
[0128] As shown in FIG. 11, the computing device cluster includes at least one computing device 1000. The memory 1006 in one or more of the computing devices 1000 in the computing device cluster can have the same instructions stored thereon for performing the steps performed by the apparatus 200 in the method of FIG. 2.
[0129] In some possible implementation, the memory 1006 of one or more of the computing devices 1000 in the computing device cluster can also respectively store partial instructions for performing the steps performed by the apparatus 200 in the method shown in FIG. 2. In other words, the combination of one or more of the computing devices 1000 can collectively perform the instructions for performing the steps performed by the apparatus 200 in the method shown in FIG. 2.
[0130] It should be noted that the memory 1006 in different computing devices 1000 in the computing device cluster can store different instructions respectively for performing partial functions of the apparatus 1000. That is, the instructions stored in the memory 1006 in different computing devices 1000 can implement the functions of one or more of the receiving module 910, the checking module 920, the generating module 930, the determining module 940 and the repairing module 950.
[0131] In some possible implementation, one or more of the computing devices in the computing device cluster can be connected through a network. The network can be a wide area network, a local area network, or the like. FIG. 12 shows one possible implementation. As shown in FIG. 12, two computing devices 1000A and 1000B are connected through a network. Specifically, the computing devices are connected to the network through the communication interfaces in the computing devices. In this type of possible implementation, the memory 1006 in the computing device 1000A stores instructions for performing the functions of the receiving module 910 and the checking module 920. Meanwhile, the memory 1006 in the computing device 1000B stores instructions for performing the functions of the generating module 930, the determining module 940 and the repairing module 950.
[0132] It should be understood that the functions of the computing device 1000A shown in FIG. 12 can also be completed by multiple computing devices 1000. Similarly, the functions of the computing device 1000B can also be completed by multiple computing devices 1000.
[0133] Embodiments of the present application also provide another computing device cluster. The connection relationship between the computing devices in the computing device cluster can be similar to the connection manners of the computing device clusters described with reference to FIG. 11 and FIG. 12. The difference is that the memory 1006 in one or more of the computing devices 1000 in the computing device cluster can store the same instructions for performing the steps performed by the apparatus 200 in the method shown in FIG. 2.
[0134] In some possible implementation, the memory 1006 of one or more of the computing devices 1000 in the computing device cluster can also respectively store partial instructions for performing the steps performed by the apparatus 200 in the method shown in FIG. 2. In other words, the combination of one or more of the computing devices 1000 can collectively perform the instructions for performing the steps performed by the apparatus 200 in the method shown in FIG. 2.
[0135] The embodiment of the present application further provides a computer program product containing instructions. The computer program product can be a software or program product containing instructions, which can run on a computing device or be stored in any available medium. When the computer program product runs on at least one computing device, the at least one computing device is caused to perform the steps performed by the apparatus 200 in the method shown in Fig. 2.
[0136] The embodiment of the present application further provides a computer readable storage medium. The computer readable storage medium can be any available medium that the computing device can store or a host migration device such as a data center containing one or more available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk), etc. The computer readable storage medium contains instructions, which instruct the computing device to perform the steps performed by the apparatus 200 in the method shown in Fig. 2.
[0137] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the protection scope of the technical solutions of the embodiments of the present application.
Claims
1. A program defect repair method characterized by comprising: The method comprises: receiving program code input by a user; code inspection on the program code; when a code defect is detected in the program code, generating a plurality of code patches for the code defect respectively by a plurality of code repair tools, wherein each code repair tool of the plurality of code repair tools corresponds to generate a code patch; determining a candidate code patch for each tool type from the plurality of code patches according to a plurality of tool types to which the plurality of code repair tools belong, wherein each code repair tool of the plurality of code repair tools has a tool type, and there are at least two tool types to which the plurality of code repair tools belong; repairing the code defect by using a target code patch, wherein the plurality of candidate code patches of the plurality of tool types include the target code patch.
2. The method of claim 1, wherein, The plurality of tool types includes at least one tool type selected by the user, and the method further comprises: providing a code repair tool interface to the user, wherein the code repair tool interface records the code defect and a plurality of candidate tool types; selecting the at least one tool type from the plurality of candidate tool types in response to a first selection operation input by the user.
3. The method according to claim 1 or 2, characterized in that, At least two tool types of the plurality of tool types are selected by using at least two selection strategies, wherein each selection strategy of the at least two selection strategies is used to select at least one tool type of the at least two tools; The at least two selection strategies include at least two of a first selection strategy, a second selection strategy and a third selection strategy; wherein The first selection strategy is used to select a tool type with patch generation capability, the second selection strategy is used to select a tool type based on historical repair information corresponding to a defect type, and the third selection strategy is used to select a tool type based on demand information of the user; the patch generation capability is the patch generation capability required by the code defect, and the defect type is the type to which the code defect belongs.
4. The method according to any one of claims 1 to 3, characterized in that, At least two code repair tools of the plurality of code repair tools belong to the same tool type; and determining a candidate code patch for each tool type from the plurality of code patches according to a plurality of tool types to which the plurality of code repair tools belong comprises: using a first code patch or a second code patch of at least two code patches generated by the at least two code repair tools as a candidate code patch of a tool type to which the at least two code repair tools belong; wherein The first code patch is one of at least one code patch whose opinion convergence degree is greater than a first threshold in the at least two code patches, and the opinion convergence degree of the first code patch is positively correlated with the number of code patches in the at least two code patches that have a similarity greater than a second threshold with the first code patch; The second code patch is one of at least one code patch that can repair the code defect in the at least two code patches.
5. The method according to any one of claims 1-4, characterized in that, The method comprises: The code patch interface is provided to the user, and the code patch interface records at least two candidate code patches in the plurality of candidate code patches; In response to a second selection operation input by the user, the target code patch is selected from the at least two candidate code patches.
6. The method of claim 5, wherein, The code patch interface also records a repair explanation of each of the at least two code patches.
7. The method according to claim 5 or 6, characterized in that, The code repair tool that generates the code patch also generates a first repair explanation of the code patch, and the code patch interface provided to the user includes: Each candidate code patch in the plurality of candidate code patches is input to a large language model, so that the large language model outputs a second repair explanation of the candidate code patch; Based on the similarity between the second repair explanation of each candidate code patch in the plurality of candidate code patches and the first repair explanation of the candidate code patch, the at least two candidate code patches are selected from the plurality of candidate code patches.
8. A program defect repair apparatus characterized by comprising: The device comprises: A receiving module for receiving program code input by a user; An inspection module for performing code inspection on the program code; A generating module for generating a plurality of code patches for a code defect in the program code using a plurality of code repair tools when the code defect is detected, wherein each code repair tool in the plurality of code repair tools corresponds to a generated code patch; A determining module for determining a candidate code patch for each tool type from the plurality of code patches according to a plurality of tool types to which the plurality of code repair tools belong, wherein each code repair tool in the plurality of code repair tools has a tool type, and there are at least two tool types to which the plurality of code repair tools belong; A repair module for repairing the code defect using a target code patch, wherein the plurality of candidate code patches of the plurality of tool types includes the target code patch.
9. The apparatus of claim 8, wherein, The plurality of tool types includes at least one tool type selected by the user, and the generating module is configured to: Provide a code repair tool interface to the user, wherein the code repair tool interface records the code defect and a plurality of candidate tool types; In response to a first selection operation input by the user, select the at least one tool type from the plurality of candidate tool types.
10. The apparatus of claim 8 or 9, wherein, At least two tool types in the plurality of tool types are selected using at least two selection strategies, wherein each selection strategy in the at least two selection strategies is used to select at least one tool type in the at least two tools; The at least two selection strategies include at least two of a first selection strategy, a second selection strategy, and a third selection strategy; wherein The first selection strategy is used to select a tool type with patch generation capability, the second selection strategy is used to select a tool type based on historical repair information corresponding to a defect type, and the third selection strategy is used to select a tool type based on demand information of the user; the patch generation capability is a patch generation capability required by the code defect, and the defect type is a type to which the code defect belongs.
11. The apparatus of any one of claims 8-10, wherein, The at least two code repair tools in the plurality of code repair tools belong to the same tool type; the determination module is configured to: use a first code patch or a second code patch in at least two code patches generated by the at least two code repair tools as a candidate code patch of the tool type to which the at least two code repair tools belong; wherein, the first code patch is one of at least one code patch in the at least two code patches whose opinion convergence degree is greater than a first threshold value, and the opinion convergence degree of the first code patch is positively correlated with the number of code patches in the at least two code patches that have a similarity greater than a second threshold value with the first code patch; the second code patch is one of at least one code patch in the at least two code patches that can repair the code defect.
12. The apparatus of any one of claims 8-11, wherein, The repair module is configured to: provide a code patch interface to the user, the code patch interface recording at least two candidate code patches in the plurality of candidate code patches; select the target code patch from the at least two candidate code patches in response to a second selection operation input by the user.
13. The apparatus of claim 12, wherein, The code patch interface also records a repair explanation of each code patch in the at least two code patches.
14. The apparatus of claim 8 or 13, wherein, The code repair tool that generates the code patch also generates a first repair explanation of the code patch, and the repair module is configured to: input each candidate code patch in the plurality of candidate code patches into a large language model, so that the large language model outputs a second repair explanation of the candidate code patch; select the at least two candidate code patches from the plurality of candidate code patches based on a similarity between the second repair explanation of each candidate code patch in the plurality of candidate code patches and the first repair explanation of the candidate code patch.
15. A cluster of computing devices, characterized in that, at least one computing device, each computing device including a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the computing device cluster to perform the method of any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, computer program instructions that, when executed by a computing device cluster, cause the computing device cluster to perform the method of any one of claims 1 to 7.
17. A computer program product comprising instructions, characterized in that, when the instructions are run by a computer device cluster, cause the computer device cluster to perform the method of any one of claims 1 to 7.
Citation Information
Patent Citations
Rule-based automatic program repair method, storage medium and computing device
CN111124922A
Code defect repair scheme recommendation method and device, equipment and storage medium
CN114647432A
Code vaccine-based real-time vulnerability repair method and device, equipment and medium
CN116992438A
Prioritization of software patches
US20180011700A1