Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception message for invalid token is unclear #8932

Closed
romani opened this issue Oct 28, 2020 · 0 comments · Fixed by #9200
Closed

Exception message for invalid token is unclear #8932

romani opened this issue Oct 28, 2020 · 0 comments · Fixed by #9200
Milestone

Comments

@romani
Copy link
Member

romani commented Oct 28, 2020

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

one more case - checkstyle/sonar-checkstyle#338 (comment)

Expected:
java.lang.IllegalArgumentException: unknown TokenTypes value ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant