English

The Impact of Mutability on Cyclomatic Complexity in Java

Software Engineering 2024-10-15 v1

Abstract

In Java, some object attributes are mutable, while others are immutable (with the "final" modifier attached to them). Objects that have at least one mutable attribute may be referred to as "mutable" objects. We suspect that mutable objects have higher McCabe's Cyclomatic Complexity (CC) than immutable ones. To validate this intuition, we analysed 862,446 Java files from 1,000 open-GitHub repositories. Our results demonstrated that immutable objects are almost three times less complex than mutable ones. It can be therefore assumed that using more immutable classes could reduce the overall complexity and maintainability of the code base.

Cite

@article{arxiv.2410.10425,
  title  = {The Impact of Mutability on Cyclomatic Complexity in Java},
  author = {Marat Bagaev and Alisa Khabibrakhmanova and Georgy Sabaev and Yegor Bugayenko},
  journal= {arXiv preprint arXiv:2410.10425},
  year   = {2024}
}
R2 v1 2026-06-28T19:20:28.476Z