Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML output printed to standard output is invalid when there any errors in the code #1018

Closed
michalsvagerka opened this issue Apr 29, 2015 · 2 comments
Assignees
Milestone

Comments

@michalsvagerka
Copy link

STEPS TO REPRODUCE:

  1. Create file Foo.java with contents: class Foo { }
  2. Run: checkstyle-6.6.jar -f xml -c /sun_checks.xml Foo.java

Exception is thrown and usage is printed, even though the results are produced. This breaks any tool that parses the resulting XML from standard output.

ACTUAL STDOUT:

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="6.6">
<file name="/tmp/Foo.java">
<error line="0" severity="error" message="Missing package-info.java file." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck"/>
<error line="1" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"/>
</file>
</checkstyle>
usage: java com.puppycrawl.tools.checkstyle.Main [options] -c <config.xml>
            file...
 -c <arg>   Sets the check configuration file to use.
 -f <arg>   Sets the output format. (plain|xml). Defaults to plain
 -o <arg>   Sets the output file. Defaults to stdout
 -p <arg>   Loads the properties file
 -v         Print product version and exit

ACTUAL STDERR:

Could not execute Checkstyle: Checkstyle ends with 2 errors.
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Checkstyle ends with 2 errors.
    at com.puppycrawl.tools.checkstyle.Main.processCommandLine(Main.java:160)
    at com.puppycrawl.tools.checkstyle.Main.main(Main.java:59)

EXPECTED RESULT:
Just the XML with errors found is printed to stdout. No exception is thrown, as the case of having errors in source files is not exceptional.
No usage should printed, as the tool was invoked correctly.

NOTES:
This is a regression from CheckStyle 6.5.
This works correctly when the output is printed to XML file (specified in '-o').

@romani
Copy link
Member

romani commented May 6, 2015

fixed during #596

after update it output like :

$ java -jar checkstyle-6.7-SNAPSHOT-all.jar -f xml -c /sun_checks.xml Test.java
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="6.7-SNAPSHOT">
<file name="/home/rivanov/tmp/cs_tests/Test.java">
......
</file>
</checkstyle>
Checkstyle ends with 12 errors.
✘-12 ~/tmp/cs_tests 

Attention to last lines, there is non XML content from CLI and error code is amount of violations with Error severity.

For plain text it is :

$ java -jar checkstyle-6.7-SNAPSHOT-all.jar -f plain -c /sun_checks.xml Test.java
Starting audit...
.....
/home/rivanov/tmp/cs_tests/Test.java:12:47: 'tests' hides a field.
Audit done.
Checkstyle ends with 12 errors.
✘-12 ~/tmp/cs_tests 

In 6.5 there were no "Checkstyle ends with XXXXX errors." in xml and plain mode.

I need to think what will be better to have "Checkstyle ends with XXXXX errors." or not.

@romani
Copy link
Member

romani commented May 6, 2015

console output is mixture of Checkstyle validation output and some CLI response, it was in 6.5 and will be always. I understand that it might cause you inconvenience is wrapping, but console output is not reliable for strict structure output. We should be in illusion that we could rely on certain structure on console out put, it even good that right now we clearly show that.

If you need clear validation output and you rely on it result please use "-o" option, in that output will never be stacktraces and other unexpected crash messages and argument validation messages that are not related to java code validation.

Structure of console output is (each part is optional):

<cli output>
<checkstyle java validation output>
<cli output>

"cli ouput" is a usage or any messages from CLI about arguments validation, at event footer message about final status and nothing about java validation.

"checkstyle java validation output" - is output of java validation only, that is independent from a way it was executed (cli, from gui , from application as embedded system, from web serivice, .... )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants