[LANG-1804] Fix CharSet#getInstance returns null instead of EMPTY when input setStrs is null
// 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ï¼
// Test NullPointerException
  @Test
  void testGetInstance_Null_Fixed_ReturnsEmpty_NoNPE() {
    CharSet charSet = CharSet.getInstance(null);
    assertThrows(NullPointerException.class,()->charSet.contains('['));
  }
@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).
Jira: https://issues.apache.org/jira/browse/LANG-1804