spotbugs / spotbugs-maven-plugin

Maven Mojo Plug-In to generate reports based on the SpotBugs Analyzer
https://spotbugs.github.io/spotbugs-maven-plugin/
Apache License 2.0
69 stars 51 forks source link

XML file encoding is missing in XML output file #73

Closed LoloDigi closed 4 years ago

LoloDigi commented 5 years ago

With the last spotbugs-maven-plugin, in 3.1.6 version, I'm not able to generate the maven-site report. It was OK with findbugs, but I can't make it work with spotbugs. My source and report encodings are CP1252 (I have many other reports like checkstyle, dependencies, javadoc, ...).

The generated spotbugsXml.xml does not contains a line like : <?xml version="1.0" encoding="CP1252"?>

So the maven-site plugin fails (assuming it is UTF-8) on the following error : Error during site generation: Invalid byte 2 of 3-byte UTF-8 sequence I was expecting that the outputEncoding parameter could set the XML encoding, but not.

Is that a bug or did I missed something ?

KengoTODA commented 5 years ago

Have you tried https://maven.apache.org/plugins/maven-site-plugin/site-mojo.html#inputEncoding ?

It's also nice to have minimum project that can reproduce your problem.

LoloDigi commented 5 years ago

Yes I did, with many values (ISO-8859-1, CP1252, UTF-8, ...) and combinations with many "outputEncoding" also. Perhaps most of projects are working in UTF-8...

hazendaz commented 5 years ago

@LoloDigi Can you provide a sample project that causes this issue?

It is true most projects are UTF-8 as that is the universal standard. You might want to determine a specific reason why your code base wants to use a legacy character encoding. Generally I've seen that used just due to improper setup when UTF-8 was fine but certainly we should work with any and a sample will help us better isolate the issue. Thanks in advance!

LoloDigi commented 5 years ago

capture What do you need exactly ? Here the content of the XML generated by spotbugs maven plugin.

`

D:\workspaceSts\courrier-project\flowbean-grc-core\target\classesC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-core\7.6.24\fm-core-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-common\7.6.24\fm-common-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-basic\7.6.24\fm-basic-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-util\7.6.24\fm-util-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\org\exolab\castor\0.9.3.21-flowmind\castor-0.9.3.21-flowmind.jarC:\Users\L.GUIRAUD\.m2\repository\org\apache\velocity\velocity\1.6.4\velocity-1.6.4.jarC:\Users\L.GUIRAUD\.m2\repository\oro\oro\2.0.8\oro-2.0.8.jarC:\Users\L.GUIRAUD\.m2\repository\commons-beanutils\commons-beanutils\1.9.2\commons-beanutils-1.9.2.jarC:\Users\L.GUIRAUD\.m2\repository\commons-logging\commons-logging\99.0-does-not-exist\commons-logging-99.0-does-not-exist.jarC:\Users\L.GUIRAUD\.m2\repository\javax\activation\activation\1.1\activation-1.1.jarC:\Users\L.GUIRAUD\.m2\repository\commons-collections\commons-collections\3.1\commons-collections-3.1.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-gui\7.6.24\fm-gui-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\api\fm-api-interaction\7.6.24\fm-api-interaction-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-data\7.6.24\fm-data-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\com\akazi\flowmind\lib\fm-antlr\7.6.24\fm-antlr-7.6.24.jarC:\Users\L.GUIRAUD\.m2\repository\org\json\json\20140107\json-20140107.jarC:\Users\L.GUIRAUD\.m2\repository\com\ibm\icu\icu4j\53.1\icu4j-53.1.jarD:\workspaceSts\courrier-project\flowbean-grc-core\src\main\javaD:\workspaceSts\courrier-project\flowbean-grc-core\targetLa m�thode clone() n'appelle pas super.clone()La m�thode clone() com.digitech.flowmind.object.DiffusionObject.clone() n'appelle pas super.clone()At DiffusionObject.java:[lines 25-403]In class com.digitech.flowmind.object.DiffusionObjectIn method com.digitech.flowmind.object.DiffusionObject.clone()At DiffusionObject.java:[line 169]Bad practiceLa m�thode clone() n'appelle pas super.clone()
<p>Cette classe d�finit une m�thode <code>clone()</code> qui n'appelle pas <code>super.clone()</code>, et n'est pas finale. Si cette classe ("<i>A</i>") est �tendue par une classe fille ("<i>B</i>"), et que la classe fille <i>B</i> appelle <code>super.clone()</code>, alors il est probable que la m�thode <code>clone()</code> de <i>B</i> retournera un objet de type <i>A</i>, ce qui viole le contrat standard de <code>clone()</code>.</p> <p>Si toutes les m�thodes <code>clone()</code> appellent <code>super.clone()</code>, elles ont alors la garantie d'utiliser <code>Object.clone()</code>, qui retourne toujours un objet du type correct.</p>
Mauvaise impl�mentation de l'idiome Cloneable
` I put a screenshot for the 'real' display in my intellij. And as text for all the content : [spotbugsXml.txt](https://github.com/spotbugs/spotbugs-maven-plugin/files/2278021/spotbugsXml.txt)
hazendaz commented 5 years ago

A small sample project that also has the issue, simple hello world will do.

jflecomte commented 5 years ago

I have the same issue. My OS (Windows 10) is configured in french. I was able to workaround the issue by configuring the language like this:

         <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <configuration>
                    <jvmArgs>-Duser.language=en</jvmArgs>
                </configuration>
            </plugin>
        </plugins>

To reproduce the error you can set "fr" instead of "en" and run "mvn install site" on a project that contains issues detected by SpotBug.

hazendaz commented 5 years ago

@jflecomte Thanks, I'll take a deeper look as soon as I can.

LoloDigi commented 5 years ago

@jflecomte The workaround is working great. Thank you for your support !

hazendaz commented 5 years ago

I'm not very good with groovy :( I took a stab at fixing the issue. I can get the xml to generate with the xml declaration but then it fails later when running a slurper against it as the declaration tag is not allowed. As the spotbugsXml.xml is just a smaller cut of spotbugsTemp.xml, I suspect that portion of the code is actually correct. It's possible later on it must be interpretted differently.

hazendaz commented 4 years ago

Issue resolved and will be available in plugin for spotbugs 4.0.0.