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/17 12:22:08 UTC

[PR] [LANG-1804] Fix CharSet#getInstance returns null instead of EMPTY when input setStrs is null [commons-lang]

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

   ```
   // source code
   public static CharSet getInstance(final String... setStrs) {
       if (setStrs == null) {
           return null; // error
       }
       if (setStrs.length == 1) {
           final CharSet common = COMMON.get(setStrs[0]);
           if (common != null) {
               return common;
           }
       }
       return new CharSet(setStrs);
   } 
   ```
   The getInstance method of CharSet currently returns null when the input parameter setStrs is null. This behavior contradicts the documentation, which states that a null input should return the EMPTY constant (an empty character set). Returning null can lead to NullPointerException in calling code that expects a valid CharSet instance even for empty inputs.
   
   The Javadoc and source code are as follows:
   <img width="896" height="491" alt="image" src="https://github.com/user-attachments/assets/1ab28a8e-e76a-4f1f-ac50-15f005001ea5" />
   
   ```
   // Test NullPointerException
       @Test
       void testGetInstance_Null_Fixed_ReturnsEmpty_NoNPE() {
           CharSet charSet = CharSet.getInstance(null);
           assertThrows(NullPointerException.class,()->charSet.contains('['));
       } 
   ```
   


-- 
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] [LANG-1804] Fix CharSet#getInstance returns null instead of EMPTY when input setStrs is null [commons-lang]

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


-- 
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] [LANG-1804] Fix CharSet#getInstance returns null instead of EMPTY when input setStrs is null [commons-lang]

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

   @IcoreE 
   If you don't run `mvn` by itself before pushing, you'll never catch build errors like the ones that just occurred (see the instructions in the PR template).


-- 
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] [LANG-1804] Fix CharSet#getInstance returns null instead of EMPTY when input setStrs is null [commons-lang]

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

   Jira: https://issues.apache.org/jira/browse/LANG-1804
   


-- 
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