spotbugs-maven-plugin icon indicating copy to clipboard operation
spotbugs-maven-plugin copied to clipboard

org.dom4j.DocumentException: Failing reading the exclude file

Open beamerblvd opened this issue 6 years ago • 8 comments

I'm using SpotBugs 3.1.8 via the spotbugs-maven-plugin 3.1.8. I'm getting the following error. Unfortunately, this output is with maximum debug/traces turned on. There is no other information. Nothing at all indicates what's wrong with my file.

     [java] The following errors occurred during analysis:
     [java]   Unable to read filter: /path/to/project/Core/target/spotbugs-exclude.xml : Failing reading /path/to/project/Core/target/spotbugs-exclude.xml
     [java]     org.dom4j.DocumentException: Failing reading /path/to/project/Core/target/spotbugs-exclude.xml
     [java]       At edu.umd.cs.findbugs.SortedBugCollection.readXML(SortedBugCollection.java:276)
     [java]       At edu.umd.cs.findbugs.SortedBugCollection.readXML(SortedBugCollection.java:257)
     [java]       At edu.umd.cs.findbugs.ExcludingHashesBugReporter.addToExcludedInstanceHashes(ExcludingHashesBugReporter.java:57)
     [java]       At edu.umd.cs.findbugs.ExcludingHashesBugReporter.<init>(ExcludingHashesBugReporter.java:44)
     [java]       At edu.umd.cs.findbugs.FindBugs.configureBaselineFilter(FindBugs.java:529)
     [java]       At edu.umd.cs.findbugs.FindBugs2.excludeBaselineBugs(FindBugs2.java:377)
     [java]       At edu.umd.cs.findbugs.FindBugs2.configureFilters(FindBugs2.java:484)
     [java]       At edu.umd.cs.findbugs.FindBugs2.setUserPreferences(FindBugs2.java:473)
     [java]       At edu.umd.cs.findbugs.TextUICommandLine.configureEngine(TextUICommandLine.java:672)
     [java]       At edu.umd.cs.findbugs.FindBugs.processCommandLine(FindBugs.java:365)
     [java]       At edu.umd.cs.findbugs.FindBugs2.main(FindBugs2.java:1175)

I've confirmed that it's not a matter of it not finding the file, because I changed the configured name of the file and I got a different error (that the name couldn't be found). So it is definitely finding my file, it just can't parse it and won't tell me why.

Here is my plugin configuration:

<plugin>
    <groupId>com.github.spotbugs</groupId>
    <artifactId>spotbugs-maven-plugin</artifactId>
    <version>3.1.8</version>
    <configuration>
        <effort>Max</effort>
        <excludeBugsFile>build/spotbugs-exclude.xml</excludeBugsFile>
        <threshold>Low</threshold>
        <xmlOutput>true</xmlOutput>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Here is my spotbugs-exclude.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright © 2010-2019 OddSource Code ([email protected])

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<FindBugsFilter xmlns="https://github.com/spotbugs/filter/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
    <Match>
        <Class name="a.b.c.ImmutableArrayList" />
        <Bug pattern="BC_BAD_CAST_TO_CONCRETE_COLLECTION" />
    </Match>

    <Match>
        <Class name="a.b.c.ImmutableLinkedHashSet" />
        <Bug pattern="BC_BAD_CAST_TO_CONCRETE_COLLECTION" />
    </Match>

    <Match>
        <Class name="a.b.c.ObjectSerializer" />
        <Method name="readObject" />
        <Bug pattern="DE_MIGHT_IGNORE" />
    </Match>

    <Match>
        <Class name="a.b.c.FileLicenseProvider" />
        <Method name="getLicenseData" />
        <Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS" />
    </Match>
</FindBugsFilter>

I have no idea what the problem here is, but there is definitely a bug, and it's one of the following:

  • There is actually something wrong with my file (which I wrote according to the documentation), but SpotBugs does not properly tell me what that problem is in the error message.
  • There is nothing wrong with my file, bug SpotBugs is failing to parse it due to some bug in the parser.

For what it's worth, I have tried taking the xmlns/xsd stuff out of the file, and it made no difference.

beamerblvd avatar Jan 22 '19 05:01 beamerblvd

Thanks for opening your first issue here! :smiley: Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

welcome[bot] avatar Jan 22 '19 05:01 welcome[bot]

I did resolve my issue, but I still feel there's a bug here. I changed <excludeBugsFile> to <excludeFilterFile>. It was originally <excludeFilterFile>, but I had changed it to <excludeBugsFile> at some point because it wasn't working and I couldn't figure out why. Apparently, I solved whatever problem that was, but <excludeBugsFile> created a new problem for me.

I think there are two problems here:

  1. The failure to parse the file in <excludeBugsFile> should have explained what the parsing problem was. That might have clued me in what I had done.
  2. The documentation should explain the difference between <excludeBugsFile> and <excludeFilterFile>.

beamerblvd avatar Jan 22 '19 18:01 beamerblvd

Could you try to remove the comment at the beginning of your XML file? It could be problem because it makes two root elements in one file.

KengoTODA avatar Jan 23 '19 13:01 KengoTODA

What content? Are you talking about the comment? I did already try removing that without success, but it definitely does not make two root elements in one file. As I said in my comment above, I fixed it by changing <excludeBugsFile> to <excludeFilterFile>, so I think the actual problem is that <excludeBugsFile> is looking for a different schema. But the documentation doesn't explain what <excludeBugsFile> is, and the Dom4j error doesn't explain how that file violates the schema.

beamerblvd avatar Jan 23 '19 14:01 beamerblvd

Got it, thanks. You mean we need to update official guide for Maven plugin, right?

For 2, I think it is better to transfer this issue to Maven plugin project, I'll handle it. For 1, I will make a separated issue in this repo.

KengoTODA avatar Jan 24 '19 02:01 KengoTODA

@KengoTODA In the link you provided, I assume the fact that all the auto generated maven help there is blank. Is that the case? If so, I tried a few things to make the code show up but no luck. I'm not sure why it's not pulling javadocs other than possibly that this is groovy. I did make some adjustments though so the groovy docs work again and those are accessible on the site. However, that isn't quite what we want :(

hazendaz avatar Jan 28 '19 01:01 hazendaz

I'm also not sure why plugin doesn't refer existing javadoc ;(

KengoTODA avatar Jan 28 '19 04:01 KengoTODA

I too am struggling on this. Nothing I do seems to get spot-bugs to load the XML file. I cannot figure out why without additional logging.

Finally figured it out. I found an errant <excludeBugsFile> configuration item instead of <excludeFilterFile>

belugabehr avatar Feb 11 '21 15:02 belugabehr