Refactoring-Aware Patch Integration Across Structurally Divergent Java Forks

Daniel Ogenrwot, John Businge · 2025

Read Refactoring-Aware Patch Integration Across Structurally Divergent Java Forks by Daniel Ogenrwot, John Businge (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2508-06718.txt.

Introduction

Long-lived software forks drift apart as each side renames and moves code, and patches from one side stop fitting the other. Daniel Ogenrwot and John Businge studied that failure in 2025 across fourteen pairs of divergent Java variants, and built a tool that repairs the fit.

Plain cherry-picking failed on about sixty-four percent of 478 real bug-fix pull requests, mostly because refactorings had scrambled the context. Their system, RePatch, undoes refactorings on both sides, applies the patch in the aligned middle state, then replays the changes to respect each variant's shape. It rescued about half of the patches that plain tools had failed on. The authors argue patch tools need meaning, not just text.

Catalog record

CREATORDaniel Ogenrwot, John Businge
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE52 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2508-06718

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Refactoring-Aware Patch Integration Across Structurally Divergent Java Forks Daniel Ogenrwot, John Businge Abstract While most forks on platforms like GitHub are short-lived and used for social collaboration, a smaller but impactful subset evolve into long-lived forks, referred to here as variants, that maintain independent development trajectories. Integrating bug-fix patches across such divergent variants poses challenges due to structural drift, including refactorings that rename, relocate, or reorganize code elements and obscure semantic correspondence. This paper presents an empirical study of patch integration failures in 14 divergent pair of variants and introduces RePatch , a refactoring-aware integration system for Java repositories. RePatch extends the RefMerge framework, originally designed for symmetric merges, by supporting asymmetric patch transfer. RePatch inverts refactorings in both the source and target to realign the patch context, applies the patch, and replays the transformations to preserve the intent of the variant. In our evaluation of 478 bug-fix pull requests, Git cherry-pick fails in 64.4% of cases due to structural misalignments, while RePatch successfully integrates 52.8% of the previously failing patches. These results highlight the limitations of syntax-based tools and the need for semantic reasoning in variant-aware patch propagation. I Introduction Many modern software systems are derived by copying and adapting existing codebases, a practice known as forking [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] . Although many of such forks are short-lived or used for temporary collaboration, a smaller but impactful subset develops into long-lived forks, referred to in this work as variants [ 2 , 3 , 4 , 5 , 10 , 11 , 12 ] , that maintain independent development trajectories. These variants enable customization and organizational control [ 3 , 5 , 13 ] , but the structural and semantic divergence over time complicates the reuse of upstream patches such as bug fixes or enhancements. Structural and semantic divergence poses a major barrier to patch propagation. As variants undergo refactoring, such as method renaming, class movement, or interface modification [ 14 , 15 , 16 ] , syntactic similarity with the source deteriorates. Tools like Git cherry-pick , which rely on textual alignment, often fail when entities have been reorganized or renamed [ 15 , 16 ] . Even minor structural edits can cause merge conflicts or incorrect applications, requiring developers to manually identify equivalent code regions, which is a tedious and error-prone task [ 5 , 17 ] . Although LLM-based techniques like Pan et al. [ 16 ] offer a promising direction for patch adaptation, they provide limited transparency in how structural edits are resolved. Likewise, ML-based merge tools such as DeepMerge [ 18 ] and MergeBERT [ 19 ] frame merge resolution as token classification or sequence generation tasks over textual representations of code. Although they achieve strong results on benchmark datasets, their core models do not explicitly reason about structural drift or semantic refactorings, instead relying on learned token-level patterns. In addition, these models offer limited interpretability as their predictions lack insight into how structural changes influence merge outcomes. Empirical studies highlight the practical challenges of patch integration. Businge et al. [ 3 ] analyzed over 9,000 software families 1 1 1 A software family refers to a group of variants that originate from a common codebase and evolve independently over time. and found that integration between forked variants was rare, revealing the lack of effective patch propagation mechanisms. Ramkisoen et al. [ 5 ] reported over 1,000 cases each of “missed opportunities” (patches present in the source but missing in the target variant), and “effort duplication” (manual re-implementation) across 364 variant pairs. Many missed patches lagged behind by a median of 52 weeks, showing the fragility of patch reuse in clone-and-own ecosystems. Refactoring-aware tools like MolhadoRef [ 14 ] , RefMerge [ 15 ] , and IntelliMerge [ 20 ] have reduced merge conflicts in symmetric divergence scenarios where branches share recent history. However, they are not designed for asymmetric divergence, where forks evolve independently and accumulate unsynchronized structural changes. Therefore, these tools do not address the challenge of patch transfer across divergent repositories. To address these limitations, we investigate patch integration across structurally divergent software variants. These variants share a common origin, but have evolved independently, introducing structural changes that hinder patch reuse. Rather than merging entire branches, we focus on applying individual bug-fix commits previously identified as relevant but not integrated into target variants [ 5 ] . We examine how method-level refactorings affect patch transferability and present a refactoring-aware strategy that enhances Git’s cherry-pick with semantic reasoning. Our approach builds on the invert-and-replay strategy of Ellis et al. [ 15 ] , extending it to support integration between long-diverged repositories. Using RefactoringMiner [ 21 ] , we detect and invert refactorings in both source and target variants to enable patch application, then replay them to preserve structural intent. This supports a systematic assessment of how refactorings affect patch integration success across real-world divergent variants. We evaluate our approach on 478 bug-fixing patches from the PaReco dataset [ 5 ] , which catalogs missed integration opportunities across divergent variant pairs. Each case uses the merge commit from the original pull request as the integration unit. Our evaluation spans 14 variant pairs. While Git cherry-pick fails on 64.6% of these due to structural conflicts, our method successfully integrates 52.8% of the previously failing patches, substantially reducing manual effort. By explicitly modeling the structural changes that cause cherry-pick failures, our approach enables interpretable and reliable patch propagation across variant-rich ecosystems. To our knowledge, this is the first empirical study to isolate refactorings as a root cause of integration failure and assess their effect on patch reuse. Contributions. This paper makes the following contributions: • We frame patch integration between long-diverged forks as a refactoring-aware cherry-pick problem and analyze the structural barriers to reuse across independent repositories. • We present RePatch , a rule-based integration system that extends RefMerge to asymmetric settings by performing dual-sided refactoring detection, inversion, semantic patch application, and transformation replay. • Our study of 478 bug-fix pull requests across 14 Java variant pairs reveals that 91.6% of Git cherry-pick failures are due to target-side refactorings. RePatch resolves 52.8% of previously failed cases and reduces conflicts in over half of them, while introducing new conflicts in less than 4%. • We release all tools, datasets, patch traces, and integration logs to support replication and future work on variant-aware patch propagation [ 22 ] . Fig. 1: Illustration of patch integration from source to target variant. II Terminology, Problem and Concrete Examples In this section, we formally define the terminology used throughout our study and illustrate the practical challenges of patch integration in divergent forks through a concrete example. II-A Terminology for Variant-Based Patch Integration • source variant. The repository where a patch originates, typically where the bug fix was authored and merged. • target variant. The repository receiving the patch. Structural divergence may prevent direct application. • hunk. A contiguous block of line-level changes in a diff, marked by @@ -s,n +s,n @@ [ 23 , 24 , 25 ] . • patch. A set of hunks spanning one or more files, representing all code changes

Read the complete text