Editor’s introduction
The study assesses patch correctness prediction by comparing predicted labels with ground truth across four scenarios: true positive, false positive, false negative, and true negative. The research shows that integrating sequence-based features into heuristic representations improves performance on five metrics by an average of 13.5%.
Introduction
During the maintenance and evolution of modern software systems, software bugs are inevitable and may result in fatal consequences. It is increasingly time-consuming and labor-intensive for developers to manually fix detected bugs due to the rising number and complexity of software systems. For example, prior work demonstrates that developers usually spend 50% of their time on software debugging and fixing. To relieve manual debugging efforts, Automated Program Repair (APR) has been proposed to generate correct patches automatically without human intervention, and has received a great deal of attention from both academia and industry. In the past decades, a mass of APR approaches have been proposed and have made substantial progress on the number of correctly-fixed bugs, including heuristic-based, constraint-based, pattern-based, and learning-based ones.
However, the APR community has fundamentally been challenged by the patch overfitting issue due to insufficient program specifications. In particular, existing APR approaches typically adopted the generate-and-validate paradigm, i.e., generating candidate patches and leveraging the developer-written test cases to identify correct patches. In such cases, candidate patches passing the available test cases are returned, but they may not be generalized to other potential test cases, leading to overfitting patches. Previous studies demonstrate that it may take considerable time and effort for developers to filter out the overfitting patches, hindering the practical usability of off-the-shelf APR tools in real-world debugging scenarios.
Thus, to address the patch overfitting issue, various Automated Patch Correctness Assessment (APCA) approaches have been proposed to determine whether a plausible patch is indeed correct or not. Traditional APCA techniques can be categorized into two groups according to extracted features, including static and dynamic ones. Static approaches attempt to analyze code-changed patterns or code similarity based on syntactic and semantic features. For example, Tan et al. define a set of generic forbidden transformations (such as deleting functionality) for the buggy program. On the contrary, dynamic approaches usually execute candidate patches against additional test cases generated by automated test generation tools. For example, Xiong et al. generate new test cases and identify overfitting patches based on the execution trace similarity. However, static techniques may face challenges in achieving high identification precision, while dynamic techniques require intensive time to collect runtime information.
Recently, inspired by the advance of Deep Learning (DL), an increasing number of learning-based APCA techniques have been proposed to directly predict patch correctness. Different from traditional APCA, learning-based APCA is able to learn the relationships of correct and overfitting patches from corpora of patch benchmarks, thus receiving rapidly increasing attention. Such techniques typically handle the APCA problem as a code classification task with a two-fold prediction pipeline, i.e., a feature extractor and a binary classifier. The feature extractor first extracts the hidden features of patched code snippets, and the binary classifier takes the extracted features to perform patch correctness prediction. For example, He et al. extract hand-crafted features from Java programs statically and train a probabilistic model to perform patch correctness prediction. Besides, Tian et al. investigate the feasibility of embedding features to build predictive models by representing source code as a sequence of tokens. Furthermore, Lin et al. utilize abstract syntax trees (ASTs) to represent patched code snippets for patch classifier training. Thanks to the well-constructed code representations and powerful DL models, learning-based APCA techniques have achieved promising performance in the last couple of years.
heuristic-based Representation
We first consider TF-IDF for vectorizing code snippets, which has been widely adopted in prior studies. In addition, Following ODS, we adopt all 202 hand-crafted features, which are categorized into three types (i.e., code, context, and pattern) as per the original design of ODS.
TF-IDF Features. TF-IDF is a common numerical statistic that reflects the relevance of a code token to the whole code sequence. In the patch correctness task, it is able to compute a vector for the patched program based on the term frequency and inverse document frequency, thereby diminishing the significance of common stopwords and amplifying the importance of more pertinent code tokens.
Code Features. Unlike TF-IDF originally designed for natural language based on token frequency, code features further consider the syntactic and semantic features of code snippets. We utilize Coming to consider 50 code features, which can be categorized into four types, including operators, variables, statements, and AST operations.
Context Features. We consider some contextual features to discover other correlated statements around the buggy statements within the patch, which has been proven to be crucial for predicting patch correctness. These features describe under what context an action happens to an entity and we take all of these as context-affected features.
Graph-based Representation
Graph-based representation refers to extracting the graph information from the source code as code features. Existing code-related works have proposed multiple types of graph information to enhance code representation and address code-related tasks. In our study, we mainly focus on five types of graphs: control flow graph (CFG), control dependency graph (CDG), data dependency graph (DDG), program dependency graph (PDG), and code property graph (CPG). In particular, (1) CFG describes the execution flow of the program. For example, if statement A may occur right after statement B, then there must be an edge from A to B in CFG; (2) CDG describes control dependency in a program which happens when the branching result of a predicate determines the execution of the immediate statements; (3) DDG describes data dependency in a program which happens when a statement uses variables whose value depends on the execution of the previous statement; (4) PDG combines data dependency with control dependency; and (5) CPG combines several graph representations, e.g., CFG, CDG, and DDG into one graph structure, thus containing more graph edge and node information. Following prior work, we use Joern to construct graph representations and DGL to perform graph calculation.
Overall, we consider 15 code representations, including eight heuristic-based ones (i.e., TF-IDF, code, context, pattern, code & context, code & pattern, context & pattern, and code & context & patterns), one sequence-based (i.e., sub-word code sequence), one tree-based (i.e., AST), and five graph-based (i.e., CFG, CDG, DDG, PDG and CPG) features.
Model Selection
To evaluate the effectiveness of heuristic-based representation, we select three machine learning algorithms, i.e., Support Vector Machine (SVM), Naive Bayes and XGBoost. All of them have been adopted and shown impressive performance in previous APCA studies. In particular, Naive Bayes first calculates the probability of which class a sample belongs to based on independent features, then selects the most probable one as its decision. SVM attempts to find a hyperplane that can distinctly identify samples in different classes. Besides, XGBoost is an implementation of a gradient-boosting machine that is known for scalability and performance.
To evaluate the effectiveness of sequence-based representation, we choose Long-Short Term Memory (LSTM), Bi-directional LSTM (BiLSTM) network, and the encoder part of the Transformer. In particular, LSTM is a specialized recurrent neural network (RNN) for modeling long-term dependencies of sequences. Thus, LSTM is well-suited to extract the contextual semantic features containing token sequential dependencies between buggy and patched code snippets. Compared with LSTM, BiLSTM takes advantage of both forward and backward context, thus modeling the sequential dependencies between tokens in both directions of the sequence. Besides, the transformer employs multi-head attention, with the query-key mechanism to emphasize contextual information when encoding source code.
To evaluate the effectiveness of tree-based representation, we select two widely-aopted tree-aware model, i.e., Tree-Structured Long Short-Term Memory Networks (TreeLSTM) and Tree-based Convolutional Neural Network (TBCNN). In particular, TreeLSTM is a variant of the basic LSTM architecture to model tree-structured topologies, as LSTM only allows for strictly sequential information propagation. Unlike a single forget gate in the standard LSTM unit, the TreeLSTM unit contains one forget gate for each child. Thus, the Tree-LSTM unit is able to selectively incorporate information from each child and learn to emphasize semantic heads in our patch correctness assessment task. TBCNN considers that nodes with similar structures in AST should be represented in a similar way and employs continuous binary trees to model a node’s representation from its children through a single neural layer. In our work, we re-implement TBCNN with Pytorch framework and optimize the code’s CPU-heavy part to make TBCNN process large-scale tree input (5000 for maximum tree nodes, 200 for maximum children nodes), so as to support our patch correctness assessment task.
To evaluate the effectiveness of graph-based representation, we select three popular and widely-used graph neural network models, i.e., Graph Convolutional Network (GCN), Graph Attention Network (GAT), and Gated Graph Neural Network (GGNN). In particular, GCN captures the dependencies and features of nodes and their neighbors by applying convolutional processes to graphs. Thus, the neighboring information of a node is aggregated using convolutional operation and layers of networks can be stacked to enhance the learning of node features. GAT attempts to incorporate an attention mechanism in GNNs to attend over the neighborhood of a node to capture the local neighborhood information. GGNN further aggregates node information by Gated Recurrent Unit (GRU) at every iteration to learn the node representations.
RQ2: Comparison with State-of-the-art Approaches
First, when comparing with ODS, we find four types of representation continuously achieve better performance, with an average improvement of 13.05%, 16.35%, 16.53%, and 17.63%. Importantly, it can be observed that, as a representative in heuristic-based representation, TF-IDF outperforms ODS by 13.25% for accuracy, 8.43% for precision, 17.20% for recall, and 13.38% for F1, indicating that TF-IDF, as a widely-used feature in many SE tasks, remains effective in predicting patch correctness. Second, when comparing with Tian et al., we find SVM achieves optimal performance among four variants, improving LR, DT, and NB by 2.03%, 18.69%, and 8.04%, respectively. However, four types of representations achieve better performance than SVM by 4.64%, 7.69%, 7.86%, and 8.88%, and even than the context-aware approach CACHE by 2.61%, 5.60%, 5.77%, and 6.76%. Third, when comparing with PATCH-SIM, we find that tree-based representation achieves 80.00% for accuracy, 84.00% for precision, 91.00% for recall, and 88.00% for F1, three of which are superior, except precision. We think the results about precision are acceptable as dynamic execution information naturally enhances the precision, while representation-based approaches only rely on static information.
Automated Program Repair
Existing APR approaches can be categorized into four main categories according to the hypotheses to generate patches. Heuristic-based APR generates a large number of patch candidates based on syntactic program modifications and employs heuristics to explore the search space of patch generation. For example, GenProg uses genetic programming to search for a patch that passes all provided test cases and SimFix searches for code snippets from code change operations from existing patches and similar code snippets within the buggy project. Constraint-based APR transforms the patch generation into a constraint-solving problem and uses a solver to obtain a feasible solution. For example, ACS generates precise patches by ranking the ingredients for condition synthesis and is considered one of the representative approaches. Template-based APR generates patches by employing pre-defined fix patterns to mutate buggy code snippets with the retrieved donor code. For example, TBar summarizes a variety of fix patterns from the literature and GAMMA is a successor of TBar by retrieving the donor code with mask prediction on top of LLMs. Learning-based APR treats the APR problem as a neural machine translation task with the advance of DL models. For example, Recoder predicts edits to generate syntactically-correct patches with a syntax-guided edit decoder and CIRCLE can fix multilingual bugs with a single repair model based on continual learning and T5. Furthermore, recent studies have explored the use of LLMs for program repair, which can be viewed as a further extension of learning-based APR. Since this direction is not the main focus of this paper, we do not discuss it in detail; a comprehensive overview is available in the survey.
Automated Patch Correctness Assessment
Static-based APCA. Such techniques usually adopt static analysis tools to analyze the buggy program, extract some designed static features (such as context and operations), and then determine the correctness of patches based on these features. For example, ssFix utilizes token-based syntax representation to generate patches with a higher probability of correctness. Anti-patterns collects a total of 86 software bugs from 12 real-world projects and identifies a set of erroneous program modification patterns. S3 utilizes six syntactic features and semantic features to measure the distance between a candidate patch and the buggy code snippet. If the distance exceeds a pre-set threshold, the corresponding patch is identified as overfitting.
Dynamic-based APCA. Such techniques mainly identify the correctness of patches based on the results of test case execution or the program’s execution path. For example, Daikon utilizes program invariants and oracle information to explore differences between overfitting and correct patches. For a patch, if its inferred invariant is identical to the true invariant, it is considered correct. If there exists a difference, the patch is considered overfitting. Besides, DiffTGen identifies overfitting patches by measuring syntax differences between the patched and buggy programs by using an external test generator to generate new test cases and comparing the output of a patch on these test cases with that of the correct program on the same test cases. PATCH-SIM predicts patch correctness based on the assumption that the execution traces of passing tests on the buggy and patched programs may be similar, and the execution traces of failing tests on these two programs may differ.
Learning-based APCA. Such techniques attempt to predict whether a plausible patch is correct or not based on machine learning techniques. For example, ODS first extracts 202 code features at the abstract syntax tree level and trains the classifier to predict which ones are correct patches. Tian et al. propose to utilize representation learning techniques to generate an embedding for buggy and fixed code snippets, and then input them into supervised learning classifiers to predict patch correctness. Besides, CACHE is a context-aware APCA technique by considering both code context and AST structural information. Le et al. propose INVALIDATOR by utilizing program invariants and pre-trained models to perform semantic and syntactic reasoning for patch correctness. Recently, Zhang et al. propose APPT, a pre-trained model-based APCA approach by jointly fine-tuning BERT and classifiers.
Conclusion and Future Work
In this paper, we perform the first exploration to empirically investigate the feasibility of different code representations on automated patch correctness assessment. Specifically, we conduct a large-scale study to analyze the effectiveness and limitations of patch prediction approaches supported by code representation, involving 15 features from four categories, 11 classifiers, and more than 500 trained models. The results demonstrate that the graph-based representation can consistently outperform other representations, e.g., an accuracy of 83.95% for DDG with GGNN. We further demonstrate representation approaches achieve comparable or better performance against state-of-the-art approaches, such as CAHCE. We also explore the potential of fusing different types of code representation and discuss the impact of different node embeddings, such as textual and type node information. Lastly, our findings reveal practical guidelines for future representation-based patch correctness assessment studies. Overall, our work demonstrates the promising future and challenges of using code representation in reasoning about patch correctness and helping developers effectively exploit off-the-shelf APR tools in practice. In the future, we will consider more powerful models and design code representations tailored for predicting patch correctness. We also hope to introduce advanced strategies to fuse different types of code representations.


