Checkstyle: CheckstyleException: 无法找到文件,但文件存在。

huangapple go评论59阅读模式
英文:

Checkstyle: CheckstyleException: Unable to find but file exists

问题

我的 Checkstyle 配置似乎无法找到我的 suppressions.xml 文件,但该文件确实存在,并且它正在使用的文件路径是有效的。我的 checkstyle.xml 和 suppressions.xml 都在 config/checkstyle 目录下。我的 checkstyle.xml 包含以下内容:

<module name="SuppressionFilter">
    <property name="file" value="${config_loc}\suppressions.xml"/>
    <property name="optional" value="false"/>
</module>

当我运行 gradlew check --stacktrace 时,堆栈跟踪显示如下:

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: 无法找到:C:\Users\ntroncoso\Online Drive\projects\test-project\test-project-sdk\config\checkstyle\suppressions.xml
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:287)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:238)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:224)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionFilter.finishLocalSetup(SuppressionFilter.java:269)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:197)
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:477)
        ... 206 more
Caused by: java.io.FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:647)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1304)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1270)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:264)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1161)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1045)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:959)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
        at com.puppycrawl.tools.checkstyle.XmlLoader.parseInputSource(XmlLoader.java:86)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:283)

正如我提到的,我可以将该文件路径复制粘贴到文件浏览器中并打开。我还尝试过直接硬编码完整路径,但是我收到了相同的错误。我唯一能想到的是 \ntroncoso 部分。某些系统会将其视为路径中的换行符。但通常情况下,错误信息也会打印出换行符,所以我觉得这不是问题所在。

英文:

My Checkstyle configuration cannot seem to find my suppressions.xml, but it does exist and the filepath it is using works. Both my checkstyle.xml and suppressions.xml are in config/checkstyle. My checkstyle.xml has this:

&lt;module name=&quot;SuppressionFilter&quot;&gt;
    &lt;property name=&quot;file&quot; value=&quot;${config_loc}\suppressions.xml&quot;/&gt;
    &lt;property name=&quot;optional&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;

When I run gradlew check --stacktrace, the stack trace shows this:

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to find: C:\Users\ntroncoso\Online Drive\projects\test-project\test-project-sdk\config\checkstyle\suppressions.xml
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:287)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:238)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:224)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionFilter.finishLocalSetup(SuppressionFilter.java:269)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:197)
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:477)
        ... 206 more
Caused by: java.io.FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:647)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1304)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1270)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:264)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1161)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1045)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:959)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
        at com.puppycrawl.tools.checkstyle.XmlLoader.parseInputSource(XmlLoader.java:86)
        at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:283)

As I mentioned, I can copy and paste that file path into file explorer and it'll open. I tried just hardcoding the full path as well, but I get the same error. The only thing I can think of is the \ntroncoso part. Some systems will treat that as a new line in the path. But typically, the error would also print the new line, so I don't feel like that's the issue.

答案1

得分: 3

> 文件未找到异常:http://www.puppycrawl.com/dtds/configuration_1_3.dtd

这是您真正的错误。您的抑制文件的DTD是错误的。首先,您正在使用配置DTD来处理抑制文件。其次,puppycrawl域名已过时,目前已迁移到checkstyle.org。

DTD应更改为https://checkstyle.org/dtds/suppressions_1_2.dtd,这是此时最新版本Checkstyle的最新DTD。

请参阅https://github.com/checkstyle/checkstyle/blob/master/config/suppressions.xml,了解正确抑制文件的示例。

英文:

> FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd

This is your true error. The DTD of your suppression file is wrong. First, you are using a configuration DTD for a suppression file. Second, puppycrawl domain is outdated and has since moved to checkstyle.org .

The DTD should be changed to https://checkstyle.org/dtds/suppressions_1_2.dtd which is the latest DTD for the latest version of Checkstyle at this time.

Please see https://github.com/checkstyle/checkstyle/blob/master/config/suppressions.xml for an example of a proper suppression file.

huangapple
  • 本文由 发表于 2020年5月3日 21:03:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/61574901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定