Skip to content

refactor: improve code quality by enforcing final on utility classes and extracting complex methods#3049

Open
nafisa1602 wants to merge 18 commits into
google:mainfrom
nafisa1602:refactor/constructor-constructor
Open

refactor: improve code quality by enforcing final on utility classes and extracting complex methods#3049
nafisa1602 wants to merge 18 commits into
google:mainfrom
nafisa1602:refactor/constructor-constructor

Conversation

@nafisa1602

Copy link
Copy Markdown

What issues were addressed

  • Class With Only Private Constructors Should Be Final: Made NumberLimits,
    PreJava9DateFormatProvider, ReflectionAccessFilterHelper, TroubleshootingGuide,
    FormattingStyle, ISO8601Utils, and SqlTimestampTypeAdapter final
  • Loose Coupling: Changed ArrayDeque to Deque interface in GsonBuilder
  • Cognitive Complexity/ Cyclomatic Complexity: Extracted excludeField() checks
    into private named methods in Excluder

Why the changes improve the system

  • final on utility classes prevents unintended subclassing and communicates
    design intent clearly to future maintainers
  • Interface types over implementation types improves flexibility
  • Extracted methods reduce cognitive complexity of excludeField() from 18 to
    near 0 and make each exclusion rule independently readable and testable

Refactoring approach

Extract Method and programming to interfaces patterns, guided by PMD static analysis.

Functionality unchanged

All 4603 existing tests pass with 0 failures after every change.

@google-cla

google-cla Bot commented Jun 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Marcono1234 Marcono1234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The changes look mostly good to me. I have added two comments, feel free to consider them only as suggestions.
The direct project members might have additional comments.

jsonAdapterFactory,
newImmutableList(reflectionFilters)));

factories.trimToSize();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be worth discussing whether this trimToSize() here is really needed or is premature optimization, but since the purpose of your PR is only to use "interface types over implementation types", I think this functionality change should be reverted for this PR. That is, please change the local variable back to ArrayList and add back the trimToSize() call.

Generally "interface types over implementation types" is a good principle, but for internal code it is bit less relevant, even more so if this only applies to a local variable and the specific implementation type is needed because the needed functionality does not exist for the interface type (as it is the case here).

Comment thread .gitignore Outdated
build

.DS_Store
apache-maven-3.9.6-bin.tar.gz

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please revert this? It seems to be specific to your development setup and is probably not useful for most other contributors.

…List with trimToSize, remove maven tarball from gitignore
@nafisa1602

nafisa1602 commented Jun 30, 2026 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants