[
https://issues.apache.org/jira/browse/LANG-1804?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary D. Gregory resolved LANG-1804.
-----------------------------------
Fix Version/s: 3.20.1
Resolution: Fixed
[~zhongxin]
I fixed the PR and merged it.
Please verify your use case with git master or a snapshot build from
[https://repository.apache.org/content/repositories/snapshots/], then close
this ticket if appropriate.
Thank you!
> Fix CharSet#getInstance returns null instead of EMPTY when input setStrs is
> null
> --------------------------------------------------------------------------------
>
> Key: LANG-1804
> URL: https://issues.apache.org/jira/browse/LANG-1804
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.20.0
> Reporter: Zhongxin Yan
> Priority: Major
> Fix For: 3.20.1
>
> Attachments: image-2025-12-17-20-03-49-458.png,
> image-2025-12-17-20-12-40-410.png, image-2025-12-17-20-13-49-838.png,
> image-2025-12-17-20-14-35-234.png
>
>
>
> {code:java}
> // 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);
> } {code}
> 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. [github
> PR|https://github.com/apache/commons-lang/pull/1530]
> The Javadoc and source code are as follows:
> !image-2025-12-17-20-14-35-234.png|width=441,height=259!
>
> {code:java}
> // Test NullPointerException
> @Test
> void testGetInstance_Null_Fixed_ReturnsEmpty_NoNPE() {
> CharSet charSet = CharSet.getInstance(null);
> assertThrows(NullPointerException.class,()->charSet.contains('['));
> } {code}
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)