You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "IcoreE (via GitHub)" <gi...@apache.org> on 2025/12/04 15:25:31 UTC

[PR] Non-final Static Singleton Variables Break Thread Safety and Singleton Design in RandomStringUtils [commons-lang]

IcoreE opened a new pull request, #1513:
URL: https://github.com/apache/commons-lang/pull/1513

   The RandomStringUtils class exposes three primary singleton instances (INSECURE, SECURE, SECURE_STRONG) through static fields that are currently missing the final keyword.
   
   ```
   private static RandomStringUtils INSECURE = new RandomStringUtils(RandomUtils::insecure);
   
   private static RandomStringUtils SECURE = new RandomStringUtils(SECURE_SUPPLIER);
   
   private static RandomStringUtils SECURE_STRONG = new RandomStringUtils(RandomUtils::secureStrong);
    
   ```
   Key Issues Caused by Non-final Modifier:
   
   1. Unintended Reassignment: The variables can be modified at runtime (e.g., via reflection, accidental code changes, or subclassing), breaking the singleton contract and leading to inconsistent random string generation behavior across the application.
   2. Violation of Documentation: The class Javadoc explicitly labels it #ThreadSafe#, but non-final static state undermines this promise.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Make private static variables final in RandomStringUtils [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #1513:
URL: https://github.com/apache/commons-lang/pull/1513


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Make private static variables final in RandomStringUtils [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1513:
URL: https://github.com/apache/commons-lang/pull/1513#issuecomment-3612898736

   @IcoreE 
   PR merged, thank you.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org