Back to search

Queen's University at Kingston

Evaluating and Improving the Reliability of LLM-Generated Code Refactorings

Abstract

dc:description.abstract

With the rapid advancement of Large Language Models (LLMs), there is growing interest in leveraging these models to automate software engineering tasks such as code refactoring. Code refactoring aims to improve the internal quality of software systems without altering their external behavior, making it a critical activity for long-term maintainability. While prior work has demonstrated the potential of LLMs to assist with refactoring, a comprehensive understanding of their effectiveness and limitations in realistic development settings remains underexplored. This gap is important because unreliable automated refactoring can introduce subtle behavioral regressions, increase debugging effort, and reduce developer trust in AI-assisted software engineering tools. Understanding when LLM-based refactoring succeeds or fails is therefore essential for safely integrating these models into practical development workflows. In this thesis, we present an empirical investigation of LLM-driven code refactoring and propose methods to improve its reliability. We first evaluate the refactoring capabilities of five state-of-the-art LLMs, StarCoder2, LLaMA 3, GPT-4o mini, GPT-4o, and DeepSeek-v3, across 30 open-source Java projects. We assess their ability to improve static code quality, reduce code smells, and preserve functional correctness through unit test execution. Our results show that closed-source production models, such as GPT-4o and DeepSeek-v3, achieve unit test pass rates exceeding 90% in multi-file refactoring scenarios, while LLaMA 3 achieves the highest reduction in code smells. We further demonstrate that prompt engineering techniques, such as chain-of-thought and one-shot prompting, can enhance both correctness and diversity of refactorings. Despite these results, we find that LLM-generated refactorings frequently introduce functional regressions. To address this limitation, we analyze failure cases, identifying key causes such as context misunderstanding, inconsistent renaming, and incomplete code generation. Building on these insights, we design an automated, test-guided repair framework that incorporates static analysis, unit test feedback, explanation agents, and project-level context to iteratively correct faulty refactorings. Our strongest configuration repairs 70.8% of the failures remaining after static repair, increasing the cumulative unit test pass rate to 94.2%. Overall, this thesis provides empirical evidence and practical repair strategies that support the development of more reliable LLM-based refactoring assistants for real-world software maintenance.

Degree

thesis:*
Department dc:contributor.department
Electrical and Computer Engineering
Grantor
Queen's University at Kingston
Year dc:date.issued
2026

Author and committee

dc:creator, dc:contributor.*
Author dc:creator
  • Cordeiro, Jonathan
Advisor dc:contributor.supervisor
  • Zou, Ying

Subjects

dc:subject × 5

Rights

dc:rights
Statement dc:rights
  • Attribution 4.0 International
Language dc:language.iso
eng

Identifiers

dc:identifier.*
Handle dc:identifier.uri
https://hdl.handle.net/1974/36882

Chain of custody

source
Harvested from
Queens University
Base URL
qspace.library.queensu.ca/server/oai/request
Last updated
2026-11-19
Source record
OAI-PMH GetRecord
citation

Cordeiro, Jonathan. Evaluating and Improving the Reliability of LLM-Generated Code Refactorings. Queen's University at Kingston, 2026. https://hdl.handle.net/1974/36882