无法实例化 MatchXpath
Posted
技术标签:
【中文标题】无法实例化 MatchXpath【英文标题】:Unable to instantiate MatchXpath 【发布时间】:2021-11-26 00:01:17 【问题描述】:我使用the Gradle plugin 设置了 Checkstyle。我正在尝试设置一个规则,强制在所有局部变量中使用 var
s。
<module name="Checker">
<module name="MatchXpath">
<property name="query"
value="//VARIABLE_DEF[./ASSIGN/EXPR and not(./TYPE/IDENT[@text='var'])]"/>
<message key="matchxpath.match"
value="Local variables should use 'var' keyword"/>
</module>
</module>
</module>
但是,上面的配置会引发以下错误。所有其他规则都可以正常工作,因此它与“MatchXpath
”模块有关。
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - cannot initialize module MatchXpath - Unable to instantiate 'MatchXpath' class, it is also not possible to instantiate it as .MatchXpath, MatchXpathCheck, .MatchXpathCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
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.ant.CheckstyleAntTask.createRootModule(CheckstyleAntTask.java:421)
... 149 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module MatchXpath - Unable to instantiate 'MatchXpath' class, it is also not possible to instantiate it as .MatchXpath, MatchXpathCheck, .MatchXpathCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
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)
... 151 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'MatchXpath' class, it is also not possible to instantiate it as .MatchXpath, MatchXpathCheck, .MatchXpathCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:215)
at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:116)
... 153 more
【问题讨论】:
【参考方案1】:MatchXpath
与 Checkstyle 8.39 一起发布。如果您至少没有那个版本,那么您使用的版本太旧了。
https://checkstyle.org/config_coding.html#MatchXpath
您应该仔细检查您正在运行的 Checkstyle 版本,如果太低则升级它。
此外,您的配置缺少TreeWalker
,因此它不是完全有效的配置。配置应该是:
<module name="Checker">
<module name="TreeWalker">
<module name="MatchXpath">
<property name="query"
value="//VARIABLE_DEF[./ASSIGN/EXPR and not(./TYPE/IDENT[@text='var'])]"/>
<message key="matchxpath.match"
value="Local variables should use 'var' keyword"/>
</module>
</module>
</module>
【讨论】:
升级版本解决了这个问题。谢谢!以上是关于无法实例化 MatchXpath的主要内容,如果未能解决你的问题,请参考以下文章
在win10上安装Oracle11g 出现无法实例化怎样解决
无法实例化页面(net.thucydides.core.webdriver.DriverConfigurationError:无法实例化类 io.appium.java_client.AppiumDr