You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe
The LettuceClassUtils, ReplicaUtils, ReflectionTestUtils class is a utility class designed to provide static helper methods, but its constructor is currently public. This allows instantiation of the class, which violates the intended usage and Java best practices for utility classes (Effective Java, Item 4: Enforce noninstantiability with a private constructor). Instantiating a utility class can lead to misuse and confusion.
Describe the solution you'd like
Change the Utility Class constructor from public to private to prevent instantiation. Additionally, add Javadoc to the class and constructor to document its purpose and noninstantiable nature. Review other utility classes (e.g., LettuceStrings, LettuceAssert) to ensure consistent use of private constructors across the project.
Proposed changes:
Update Utility Class constructor to private.
Add a unit test to verify that instantiation is not possible.
Drawbacks:
Minimal impact, as this is an internal change with no effect on the public API.
Requires review of other utility classes to ensure consistency, which may increase the scope slightly.
Describe alternatives you've considered
Keep the public constructor: This allows potential misuse and does not align with utility class best practices.
Use a static initializer: Less explicit than a private constructor and does not prevent instantiation as effectively.
Make the class abstract: Not suitable, as utility classes should not be extended.
The private constructor approach is the most explicit and aligns with standard Java practices.
The text was updated successfully, but these errors were encountered:
ori0o0p
changed the title
Enforce Noninstantiability in LettuceClassUtils with Private Constructor
Enforce Noninstantiability in Utils Class with Private Constructor
Apr 18, 2025
ori0o0p
changed the title
Enforce Noninstantiability in Utils Class with Private Constructor
Enforce Noninstantiability in Utility Class with Private Constructor
Apr 18, 2025
Feature Request
Is your feature request related to a problem? Please describe
The
LettuceClassUtils
,ReplicaUtils
,ReflectionTestUtils
class is a utility class designed to provide static helper methods, but its constructor is currentlypublic
. This allows instantiation of the class, which violates the intended usage and Java best practices for utility classes (Effective Java, Item 4: Enforce noninstantiability with a private constructor). Instantiating a utility class can lead to misuse and confusion.Describe the solution you'd like
Change the Utility Class constructor from
public
toprivate
to prevent instantiation. Additionally, add Javadoc to the class and constructor to document its purpose and noninstantiable nature. Review other utility classes (e.g.,LettuceStrings
,LettuceAssert
) to ensure consistent use ofprivate
constructors across the project.Proposed changes:
private
.Drawbacks:
Describe alternatives you've considered
public
constructor: This allows potential misuse and does not align with utility class best practices.private
constructor and does not prevent instantiation as effectively.abstract
: Not suitable, as utility classes should not be extended.The
private
constructor approach is the most explicit and aligns with standard Java practices.The text was updated successfully, but these errors were encountered: