Repository: checkstyle/checkstyle

Problem statement:
IllegalType: inability to set default value for property memberModifiers
Check documentation: https://checkstyle.org/config_coding.html#IllegalType

```

$ cat Test.java 
public class Test {
   private Optional<String> field1;
}

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="IllegalType">
            <property name="illegalClassNames" value="java.util.Optional" />
            <property name="tokens" value="VARIABLE_DEF" />
            <property name="memberModifiers" value=""/>
        </module>
   </module>
</module>

$ java -jar checkstyle-8.36.2-all.jar -c config.xml Test.java
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - cannot initialize module IllegalType - Cannot set property 'memberModifiers' to ''
  at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:482)
  at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
  at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:404)
  at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:331)
  at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:190)
  at com.puppycrawl.tools.checkstyle.Main.main(Main.java:125)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module IllegalType - Cannot set property 'memberModifiers' to ''
  at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:125)
  at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
  at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:477)
  ... 5 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Cannot set property 'memberModifiers' to ''
  at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:241)
  at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:194)
  at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:120)
  ... 7 more
Caused by: java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2128)
  at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2109)
  at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:437)
  at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:231)
  ... 9 more
Caused by: java.lang.IllegalArgumentException: given name 
  at com.puppycrawl.tools.checkstyle.utils.TokenUtil.getTokenId(TokenUtil.java:174)
  at com.puppycrawl.tools.checkstyle.checks.coding.IllegalTypeCheck.setMemberModifiers(IllegalTypeCheck.java:828)
  ... 17 more
Checkstyle ends with 1 errors.
```

Expected: work as `memberModifiers` is not mentioned in config. 


Hints:

Patch:
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java
@@ -19,12 +19,13 @@
 
 package com.puppycrawl.tools.checkstyle.checks.coding;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import com.puppycrawl.tools.checkstyle.FileStatefulCheck;
 import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
@@ -113,7 +114,7 @@
  * This property does not affect method calls nor method references.
  * Type is {@code java.lang.String[]}.
  * Validation type is {@code tokenTypesSet}.
- * Default value is {@code no tokens}.
+ * Default value is {@code ""}.
  * </li>
  * <li>
  * Property {@code tokens} - tokens to check
@@ -348,7 +349,7 @@ public final class IllegalTypeCheck extends AbstractCheck {
      * Control whether to check only methods and fields with any of the specified modifiers.
      * This property does not affect method calls nor method references.
      */
-    private List<Integer> memberModifiers;
+    private List<Integer> memberModifiers = Collections.emptyList();
 
     /** Specify RegExp for illegal abstract class names. */
     private Pattern illegalAbstractClassNameFormat = Pattern.compile("^(.*[.])?Abstract.*$");
@@ -462,7 +463,7 @@ public void visitToken(DetailAST ast) {
      */
     private boolean isVerifiable(DetailAST methodOrVariableDef) {
         boolean result = true;
-        if (memberModifiers != null) {
+        if (!memberModifiers.isEmpty()) {
             final DetailAST modifiersAst = methodOrVariableDef
                     .findFirstToken(TokenTypes.MODIFIERS);
             result = isContainVerifiableType(modifiersAst);
@@ -823,11 +824,11 @@ public void setLegalAbstractClassNames(String... classNames) {
      * @param modifiers String contains modifiers.
      */
     public void setMemberModifiers(String modifiers) {
-        final List<Integer> modifiersList = new ArrayList<>();
-        for (String modifier : modifiers.split(",")) {
-            modifiersList.add(TokenUtil.getTokenId(modifier.trim()));
-        }
-        memberModifiers = modifiersList;
+        memberModifiers = Stream.of(modifiers.split(","))
+            .map(String::trim)
+            .filter(token -> !token.isEmpty())
+            .map(TokenUtil::getTokenId)
+            .collect(Collectors.toList());
     }
 
 }


Test patch:
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java
@@ -76,6 +76,21 @@ public void testDefaults() throws Exception {
         verify(checkConfig, getPath("InputIllegalType.java"), expected);
     }
 
+    @Test
+    public void testDefaultsEmptyStringMemberModifiers() throws Exception {
+        final DefaultConfiguration checkConfig = createModuleConfig(IllegalTypeCheck.class);
+        checkConfig.addAttribute("memberModifiers", "");
+
+        final String[] expected = {
+            "17:13: " + getCheckMessage(MSG_KEY, "java.util.TreeSet"),
+            "18:13: " + getCheckMessage(MSG_KEY, "TreeSet"),
+            "43:14: " + getCheckMessage(MSG_KEY, "HashMap"),
+            "45:5: " + getCheckMessage(MSG_KEY, "HashMap"),
+        };
+
+        verify(checkConfig, getPath("InputIllegalType.java"), expected);
+    }
+
     @Test
     public void testIgnoreMethodNames() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(IllegalTypeCheck.class);
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java
@@ -1136,10 +1136,7 @@ else if (fieldClass == int[].class) {
                 if (isPropertyTokenType(sectionName, propertyName)) {
                     boolean first = true;
 
-                    if (value == null) {
-                        result = "no tokens";
-                    }
-                    else if (value instanceof BitSet) {
+                    if (value instanceof BitSet) {
                         final BitSet list = (BitSet) value;
                         final StringBuilder sb = new StringBuilder(20);