lettuce icon indicating copy to clipboard operation
lettuce copied to clipboard

Make Utility Class constructor private to enforce noninstantiability

Open ori0o0p opened this issue 8 months ago • 1 comments

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

  • [x] I have read the contribution guidelines.
  • [x] I have created a feature request first to discuss my contribution intent. See #3265
  • [x] I applied code formatting rules using the mvn formatter:format target. No formatting-related changes were submitted.
  • [x] I have submitted test cases (unit or integration tests) to back my changes, where applicable.

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.

ori0o0p avatar Apr 18 '25 02:04 ori0o0p

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 avatar May 07 '25 11:05 tishun