Published March 24, 2022 | Version v1

Is Refactoring Always a Good Egg? Exploring the Interconnection Between Bugs and Refactorings

Description

Bug fixing and code refactoring are two distinct maintenance actions with different goals. While bug fixing is a corrective change that eliminates a defect from the program, refactoring targets improving the internal quality (i.e., maintainability) of a software system without changing its functionality. Best practices and common intuition suggest that these code actions should not be mixed in a single code change. Furthermore, as refactoring aims for improving quality without functional changes, we would expect that refactoring code changes will not be sources of bugs. Nonetheless, empirical studies show that none of the above hypotheses are necessarily true in practice. In this paper, we empirically investigate the interconnection between bug-related and refactoring code changes using the SmartSHARK dataset. Our goal is to explore how often bug fixes and refactorings co-occur in a single commit (tangled changes) and whether refactoring changes themselves might induce bugs into the system. We found that it is not uncommon to have tangled commits of bug fixes and refactorings; 21% of bug-fixing commits include at least one type of refactoring on average. What is even more shocking is that 54% of bug-inducing commits also contain code refactoring changes. For instance, 10% (652 occurrences) of the Change Variable Type refactorings in the dataset appear in bug-inducing commits that make up 7.9% of the total inducing commits.

Notes

RQ1. How common it is that a bug-fixing commit contains refactoring changes as well? Our hypothesis is that bug-fixes should be independent changes not including any other types of code modifications. However, previous studies [27], [28] suggest that in practice, commits often contain tangled code changes. Therefore, we investigate how common it is that developers perform refactoring actions tangled together with bug-fixes. RQ2. Do refactoring operations appear in code modifications inducing bugs? We investigate if refactoring activities may lead to introducing bugs in the system (i.e., we can detect a bug fixing activity on the refactored code later in the commit history). For this, we analyzed if the commits marked as 'bug inducing' in the dataset also contain refactoring actions or not. RQ3. What are the most common refactoring types appearing in bug inducing commits? Finally, if we find that bug inducing changes may contain refactoring code modifications as well, we explore what are the most common types of refactorings we observe. It can help us understand what are the most 'dangerous' refactoring types where the developers need to pay special attention not to introduce bugs alongside with the modifications.

Files

ref1_inducing_result.csv

Files (66.5 kB)

Name Size
md5:507c8edfd4521abf7261a207e8784b68
6.5 kB Download
md5:e1063fe574a1c7be69f3d0c426282535
2.6 kB Download
md5:88e8db9511f0c7cce8132a51a993e6eb
3.9 kB Download
md5:159b08e9eaed910171fdc0c667e17dcc
4.0 kB Download
md5:159b08e9eaed910171fdc0c667e17dcc
4.0 kB Download
md5:b70a27314854b4c120cf13c21385bd4e
3.2 kB Download
md5:a8f4b7976ddd7963d7c85941c033c37c
4.3 kB Download
md5:865f32a477e631e1d8000fb435470680
3.5 kB Download
md5:130c2c2d95ee35cb5289e167b9a58701
2.9 kB Download
md5:46cc0ace1c1add1addc2347116a15086
8.1 kB Download
md5:e4e0208b624dd54dd2853c7a307768bd
510 Bytes Preview Download
md5:1a2dc8a43908b31b5c91d14bbd047966
805 Bytes Preview Download
md5:6b1842c213f49e73854c8d757816bd6d
3.5 kB Preview Download
md5:acd20c284965a9f45b03bf77a6fe63b7
226 Bytes Preview Download
md5:02a9f217bf1479263367381f8a5eb8f8
2.3 kB Preview Download
md5:46e922fe81fc195ae851c6e196d1a693
966 Bytes Preview Download
md5:54593f5e5200c3fea9e431fd400dfd6c
943 Bytes Preview Download
md5:5dd9590df66246a6775402eb5986bcdf
1.9 kB Preview Download
md5:2982bfcd8077b64985cc5318aba0fad4
1.4 kB Preview Download
md5:ff5231bf133c455a766d0e54b9bfe276
11.0 kB Preview Download