Skip to content

Make Utility Class constructor private to enforce noninstantiability #3266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ori0o0p
Copy link
Contributor

@ori0o0p ori0o0p commented Apr 18, 2025

Description

This PR modifies the LettuceClassUtils, ReplicaUtils, ReflectionTestUtils class to enforce noninstantiability by changing its constructor to private, aligning with Java best practices for utility classes (Effective Java, Item 4). Additionally, Javadoc is added to clarify the class's purpose and prevent misuse. Similar utility classes were reviewed to ensure consistency.

Key changes:

  • Changed LettuceClassUtils, ReplicaUtils, ReflectionTestUtils constructor to private to prevent instantiation.
  • No functional changes; maintains backward compatibility.

Related Issue

Closes #3265

Checklist

Additional Notes

  • Testing: No functional changes were made, so existing tests remain valid. Added a test to verify that LettuceClassUtils cannot be instantiated.
  • Impact: This change is internal and does not affect the public API or user-facing behavior.
  • Build Fix: Ensured compliance with formatter-maven-plugin by running mvn formatter:format and mvn formatter:validate.

- Changed constructor to private to prevent instantiation
@ori0o0p ori0o0p changed the title Make Utils Class constructor private to enforce noninstantiability Make Utility Class constructor private to enforce noninstantiability Apr 18, 2025
@tishun tishun added this to the 7.0.0.RELEASE milestone May 7, 2025
@tishun
Copy link
Collaborator

tishun commented May 7, 2025

I don't disagree with the change, but I think we can only accept it for a major release.

If somebody already uses these classes by instantiating them (which I agree is wrong, but would still work) we would break their code. So we need to target something other than a minor/patch release.

@tishun tishun requested a review from Copilot May 7, 2025 11:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Enforce Noninstantiability in Utility Class with Private Constructor
2 participants