Java Plugin - XML parse error in C# project

196 views
Skip to first unread message

Marcel

unread,
Aug 23, 2016, 9:43:50 AM8/23/16
to SonarQube
Hello,

I get the following error if I analyze a C# project with an invalid xml file

INFO: Sensor XmlFileSensor
  INFO
: 2 source files to be analyzed
EXEC
: error : Unable to parse xml file: D:\XXXXXX.xml [D:\XXXXX.targets]
  org
.xml.sax.SAXParseException: XML-Dokumentstrukturen msen innerhalb derselben Entity beginnen und enden.
   at com
.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.endEntity(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.endEntity(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLEntityManager.endEntity(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipSpaces(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.seekCloseOfStartTag(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[na:1.8.0_92]
   at com
.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source) ~[na:1.8.0_92]
   at javax
.xml.parsers.SAXParser.parse(Unknown Source) ~[na:1.8.0_92]
   at org
.sonar.java.xml.XmlParser.parseXML(XmlParser.java:59) ~[java-frontend-4.1.jar:na]
   at org
.sonar.java.xml.XmlAnalyzer.simpleScan(XmlAnalyzer.java:95) [java-frontend-4.1.jar:na]
   at org
.sonar.java.xml.XmlAnalyzer.scan(XmlAnalyzer.java:81) [java-frontend-4.1.jar:na]
   at org
.sonar.plugins.java.XmlFileSensor.execute(XmlFileSensor.java:55) [sonar-java-plugin-4.1.jar:na]
   at org
.sonar.batch.sensor.SensorWrapper.analyse(SensorWrapper.java:57) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:234) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.task.ScanTask.execute(ScanTask.java:47) [sonar-scanner-engine-shaded-5.6.1.jar:na]
   at org
.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86) [sonar-scanner-engine-shaded-5.6.1.jar:na]
  INFO
: Sensor XmlFileSensor (done) | time=112ms

 

Our Scenario:

I want to build a C# project (no java files) which contains a test case with an invalid xml file. Within the MsBuild Scanner-End-Step the Java plugins tries to parse the xml file and throws a parser error :/

Unfortunately, I cannot uninstall the java plugin because we need it for the java projects ;)

 

Is it normal that the java plugin parses the xml files whether the entire project contains no java file?

What do I wrong? Is there any workaround?

Best regards

Marcel

SonarQube 5.6.1

Java 4.1

C# 5.3.1

XML 1.4.1

MsBuildRunner 2.1

Nicolas Peru

unread,
Aug 24, 2016, 8:25:37 AM8/24/16
to Marcel, SonarQube
Hi Marcel, 

Just to be clear on the behavior you get : this is an error in your log but your analysis is finishing properly. (tell me if i'm wrong here). 
You are not doing anything wrong, this is an expected behavior as the java plugin have a bunch of rules that can be applied on xml configuration files specific to java (pom.xml, web.xml etc). 
So yes, the plugin is trying to parse those files to report issues on them. 
Why is it doing so even though you have no java files in your project ?  Because of multi module architecture in some java project you might end up with projects with no java sources but xml files that we want to analyze. So the XML sensor in java plugin is not looking at the presence of java files or not.
Maybe log should be a bit less aggressive ?

HTH, 
Cheers, 



--
Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com

Marcel

unread,
Aug 24, 2016, 9:16:28 AM8/24/16
to SonarQube, marcel.s...@gmail.com
Hi Nicolas,

Thanks for your reply.

You are right. This is an error in the log and the analysis is finishing. But the msbuild runner returns the error code -1, which breaks our tfs build.

This have the impact, that our tfs build is always red or I must ignore the the msbuild runner error code, whereby I miss other msbuild runner errors.

Yes, perhaps the log is a bit less aggressive (for example warning instead of error) or the msbuild runner returns no error code -1, if the xml sensor of the java plugin has a parse error.

Regards,
Marcel

Nicolas Peru

unread,
Aug 24, 2016, 9:45:22 AM8/24/16
to Marcel, SonarQube
Hi Marcel, 

Thanks for the confirmation. 
I don't think that the error logged and the fact that the  ms runner is returning error code -1 are actually linked. Do you have anything else in the logs ?

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/438ee52b-d07b-4a53-a3ca-53022afd419c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcel

unread,
Aug 24, 2016, 11:00:18 AM8/24/16
to SonarQube, marcel.s...@gmail.com
Hi Nicolas,

The Sensor of the XML plugin can´t analyze the xml file too. Does this cases the -1 error code? If I uninstall the XML-Plugin, all works fine.

The attachment of the email contains the log of a small project to reproduce the scenario.


regards,
Marcel
sonarqube.log

Marcel

unread,
Aug 25, 2016, 2:33:41 AM8/25/16
to SonarQube, marcel.s...@gmail.com
Hi Nicolas,

The log contains two SAXParseExceptions. One Exception is thrown by the XMLSenor (XML Pluginin) and one by the XmlFileSensor (Java-Plugin). If I uninstall the Java plugin all works fine, no -1 error code.

We are executing the msbuild runner with msbuild targets files:

<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
<Target Name="RunSonarQube">
   
<Exec Command="&quot;$(MSBuildProjectDirectory)\MSBuildRunner2_1\MSBuild.SonarQube.Runner.exe&quot; begin   /key:ParseErrorBug /name:ParseErrorBug  /version:1.0.0.0 " />
 
<MSBuild Projects="$(MSBuildProjectDirectory)\ParseErrorBug\ParseErrorBug.sln" Properties="Configuration=Release"/>
 
<Exec Command="&quot;$(MSBuildProjectDirectory)\MSBuildRunner2_1\MSBuild.SonarQube.Runner.exe&quot; end" />
 
</Target>
</Project>

 

I guess that the msbuild runner transfer the log lines with "error" at the beginning into msbuild "errors". We are executing the MsBuild-End-Step with the MsBuild-EXEC Task which gets the error log from the msbuild runner and returns the error code -1 at the end. Therefore I think that the error log of the Java-Plugin breaks the build/causes the error code -1.

I have the following question. The XML-Plugin logs the SAXParseException as INFO and the Java-Plugin as ERROR. Which is the correct log level? Should the JAVA-Plugin log the SAXParseException as INFO?


Thank you for your friendly support!

Regards,

Marcel

Julien HENRY

unread,
Aug 25, 2016, 3:44:47 AM8/25/16
to SonarQube, marcel.s...@gmail.com
Hi guys,

I you have an invalid XML file in your project used as a test resource then the solution is simple: exclude this file from SonarQube analysis. There is no point raising issues on this file.

++

Julien

Julien HENRY

unread,
Aug 25, 2016, 4:57:15 AM8/25/16
to SonarQube, marcel.s...@gmail.com
Even if I still consider that the file should be excluded, this is indeed an issue to fail the build while in fact everything goes well (ok, logging as error is a bit aggressive, but with other scanners it is harmless).

The point is that this issue was already reported and is supposed to be fixed:

So either the fix was incorrect, either Marcel you are not using the C# plugin 5.3.1.

BTW we'll try to reproduce and keep you posted.

Marcel

unread,
Aug 25, 2016, 5:46:48 AM8/25/16
to SonarQube, marcel.s...@gmail.com

Hi Julien,


Thanks, the file exclusion works.


This morning I updated the C# Plugin from 5.3.1 to 5.3.2 and I using the MSBuildRunner 2.1.

In my case the sonar-runner and the post-processor completed successfully although there was one parse error which is also a msbuild error.


Let me know if you need some information to reproduce the scenario.


Regards,

Marcel



Duarte Meneses

unread,
Aug 25, 2016, 11:35:56 AM8/25/16
to SonarQube, marcel.s...@gmail.com
Hi Marcel,

Unfortunately we were not able to reproduce the error.
The problem you are facing looks like this one, which was fixed in MsBuild Scanner 2.1:

I've just confirmed the fix with a unit test.

If you experience the problem again, please let us know, preferably with a reproducer.
Message has been deleted
Message has been deleted

Marcel

unread,
Aug 26, 2016, 4:55:56 AM8/26/16
to SonarQube, marcel.s...@gmail.com
Hi Duarte,

First of all, thanks for your investigation.

The link https://1drv.ms/u/s!AhcJ5tSLRCVZgbA4h-WQYvRicv8DPQ contains a reproducer which works for me with a new clear SonarQube 5.6.1 Server.

Let me describe the situation again, that we do not misunderstand each other. The Java-Plugin can’t parse an invalid xml test file in a C# test project and logs this SAXParseException as Error
 
EXEC
: error : Unable to parse xml file ….


The XML-Plugin can’t analyze the XML File too and logs a warning.

INFO: Cause:

  org
.xml.sax.SAXParseException: XML document structures must start and end within the same entity.


The SonarQube Scanner and the MsBuld Scanner (Post-Step) are finishing successfully.

INFO: ------------------------------------------------------------------------

 

 INFO
: EXECUTION SUCCESS

 INFO
: ------------------------------------------------------------------------

 INFO
: Total time: 7.529s

 INFO
: Final Memory: 48M/333M

 INFO
: ------------------------------------------------------------------------

 DEBUG
: Execution getVersion

 DEBUG
: Execution stop

 
Process returned exit code 0

 
The SonarQube Scanner has finished

 
09:48:56.817 Creating a summary markdown file...

 
09:48:56.818 Analysis results: http://localhost:9000/dashboard/index/ParseErrorBug

 
Post-processing succeeded.


Therefore I think that the fix SONARMSBRU-202 is correct.

In our company we are using MSBuild Targets files to execute the SonarQube analyze and build process. Therefore I execute the MSBuild Scanner with the MSBuild Task which is called EXEC. In my reproducer the targets file is called "sonar.targets". Please change the variable MSBuildRunner in the sonar.targets file. The variable have to point to an valid MsBuildRunner. You can execute the sonar.target in the cmd which the command "msbuild sonar.targets > SonarQube.log".

If I execute the MSBuildScanner with the EXEC Task, the EXEC Task failed with the Error Code -1. I guess that the MSBuildScanner (PostStep) is converting the warnings and errors in the SonarQube Scanner log into MSBuild warnings and errors. So the parse error of the java-plugin is converted to a msbuild error. The EXEC Task detects this error log and doesn’t cancel the execution but returns at the end the error code -1. So the EXEC Task generates the error code -1 and not the MSBuldRunner.

I think there is an inconsistence in the MSBuildScanner. The Runner finished with no error code but sent ERROR messages to the MSBuild Logging Framework. Either the MsBuildScanner writes an error log to the MsBuild Logging Framework and returns an error code or logs no error and has no error code -1.

Regards,

Marcel

Julien HENRY

unread,
Sep 8, 2016, 10:07:24 AM9/8/16
to SonarQube, marcel.s...@gmail.com
Hi Marcel,

Sorry for the late reply.

I have created a ticket to not forget looking more deeply to your issue during next sprint:

++

Julien

Duarte Meneses

unread,
Sep 20, 2016, 5:24:10 AM9/20/16
to SonarQube, marcel.s...@gmail.com
Hi Marcel, thanks for the reproducer.

I tried it with MSBuild 14 and the latest Scanner for MSBuild and I was not able to reproduce the problem (exit code is 0). I send attached the log.
I saw that the error messages are reported by the XML plugin due to the malformed file, but they are not translated to error messages by the Exec task in MSBuild.

If I run it with:
<Exec Command="&quot;$(MSBuildRunner)&quot; end" CustomErrorRegularExpression=".*">

Every line appears as an error, and the Exec command indeed fails, returning the code -1.

So it appears that MSBuild qualifies logs as error by applying some regexps to it. Could try to ignore it? Like this:
<Exec Command="&quot;$(MSBuildRunner)&quot; end" IgnoreStandardErrorWarningFormat="true">
output

Marcel

unread,
Oct 5, 2016, 5:14:19 AM10/5/16
to SonarQube, marcel.s...@gmail.com
Hi Duarte,

Sorry for my late reply.

I tried the workaround with the attribute IgnoreStandardErrorWarningFormat and it works for me.

Thanks a lot :)

Regards

Marcel

Reply all
Reply to author
Forward
0 new messages