# An Automatic Software Defect Repair Method Based on Multi-Objective Genetic Programming
## 3 Method and Implementation
### Repair Material  
This paper adopts the concept of redundancy hypothesis, assuming that every statement may potentially appear again in other parts of the program. It starts by obtaining a  
Figure 1: Framework Diagram of Multi-Objective Genetic Programming-Based Automatic Software Defect Repair Method. set of potentially defective statements from the defect localization stage and identifies the packages where they reside. Then it scans and examines all the code within the packages one by one. Figure 2 shows a real code snippet. Specifically, for each statement (denoted as S), it first checks whether the variables and variables in method calls of the statement fall within the scope of the suspected defective statements. If not, the repair statement can be discarded directly. Next, it verifies whether the collected statements conform to the rules in Table 1. For example, the first rule in the table states that when S is a Break or Continue statement, due to the nature of the Java language, they can only be replaced or inserted into similar loop statements. Therefore, this repair material statement can only be effective when the suspected modification point is located in a loop such as a For or While, otherwise, this repair statement will be discarded. After that, the S statement begins to verify the rules in Table 2. There are three rules related to insertion and another three related to replacement in Table 2. When statement S passes the three rules for insertion, it can proceed to the judgment of whether it can become an insertion material statement. If it passes the replacement rules, it can proceed to the judgment of a replacement material statement. If statement S passes all the rules in Table 2, it can be considered for both insertion and replacement material statement judgments. Among them, when S is selected as a replacement statement, S should have a certain similarity to the suspected modification point statement. When S is selected as an insertion statement, S should have a certain connection with the context of the modifiable point. Assuming \(V_{S}\) and \(V_{LBS}\) are the sets of variables (including local variables and fields) used by method S and method LBS respectively. After derivation, the similarity between S and LBS is defined as the Jaccard similarity coefficient between sets \(V_{S}\) and \(V_{LBS}\) as stated in Formula (2). When collecting the fields used by a statement, it is also necessary to consider the fields accessed through method calls within the current class. For the following code, if LBS is the statement return b + get(), then \(V_{LBS}=\{a,b\}\). \begin{table}
\begin{tabular}{c p{142.3 pt}} \hline \hline
**Number** & **Rules** \\ \hline
1 & Break and Continue statements can be used only when the suspect statement is in a For, While, Switch, etc. module. \\ \hline
2 & The Case statement can be used only when the suspicious statement is in the Switch module. \\ \hline
3 & Return can be used only when the method in which the suspicious statement is located declares Return. \\ \hline
4 & Return can be used when the suspicious statement is on the last line of the block code. \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Rules for Filtering Components at Each Modification Point. \begin{table}
\begin{tabular}{c p{142.3 pt}} \hline \hline
**Operation Type** & **Rule** \\ \hline Insert & Do not insert a declaration statement before a declaration statement. \\ \hline Insert & Do not insert a Return statement before a statement. \\ \hline Insert & Do not insert an assignment statement with the same left-hand side before an assignment statement. \\ \hline Replace & Do not replace a declaration statement with a statement of another type. \\ \hline Replace & Do not replace the last return statement in a method with a statement of another type. \\ \hline Replace & Do not use other types of statements to replace if-conditional statements. \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Operations to Disable Certain Specific Rules.