首页 > 解决方案 > Intellij 中的 Checkstyle 扫描期间出现异常

问题描述

我安装了 Checkstyle-Idea 插件,导入了 checkstyle 文件并使用下拉列表中的规则运行扫描。我受到以下例外的欢迎:

Unexpected Exception Caught
The scan failed due to an exception: Exception was thrown while processing /dir/.../Test.java
                Root cause:
                'other' is different type of Path
                java.lang.IllegalArgumentException: 'other' is different type of Path
                at java.base/sun.nio.fs.UnixPath.relativize(UnixPath.java:429)
                at java.base/sun.nio.fs.UnixPath.relativize(UnixPath.java:43)
                at com.puppycrawl.tools.checkstyle.utils.CommonUtil.relativizeAndNormalizePath(CommonUtil.java:382)
                at com.puppycrawl.tools.checkstyle.Checker.acceptFileStarted(Checker.java:366)
                at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:283)
                at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:216)
                at org.infernus.idea.checkstyle.service.cmd.OpScan.processAndAudit(OpScan.j... (show balloon)

互联网上其他地方没有这个例外的痕迹,这很可怕。我使用的是 8.28 版本,但我尝试使用其他旧版本并遇到了同样的问题。当我导入 checkstyle 文件时,它要求我在 checkstyle 文件中定义的 basedi 和抑制规则属性。我在两个字段中都输入了空字符串“”。

有没有人遇到过这个?

标签: javaintellij-ideacheckstyleintellij-plugin

解决方案


我对 checkstyle + gradle 有类似的问题,发现这是因为我使用了basedir属性的相对路径。将其更改为绝对路径应该可以工作(参考);

<!-- Doesn't work -->
<module name="Checker">
  <property name="basedir" value="someDirectory" />

<!-- Works -->
<module name="Checker">
  <property name="basedir" value="/home/myuser/someDirectory" />

推荐阅读