Golangci-lint error Illegal processing instruction target ("xml")

I’m using SonarQube v7.9.2, Scanner v4.2.0.1873, and the SonarGo plugin v1.6.0 (build 719)

I’m attempting to get golangci-lint issues imported by the scanner. To create the file I run:

golangci-lint run ./... --no-config --out-format checkstyle > golangci-lint.out

When the scanner runs; however, it reports this series of logs and an error:

INFO: Sensor Import of GolangCI-Lint issues [go]
INFO: Importing /var/jenkins_home/jobs/memberEnrollmentBatchService/workspace/golangci-lint.out
ERROR: No issue information will be saved as the report file '/var/jenkins_home/jobs/memberEnrollmentBatchService/workspace/golangci-lint.out' can't be read.
com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
 at [row,col {unknown-source}]: [5,5]
        at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:614)
        at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:487)
        at com.ctc.wstx.sr.BasicStreamReader.readPIPrimary(BasicStreamReader.java:3939)
        at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2062)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1131)
        at org.codehaus.stax2.ri.Stax2EventReaderImpl.nextEvent(Stax2EventReaderImpl.java:255)
        at org.sonarsource.slang.externalreport.CheckstyleFormatImporter.importFile(CheckstyleFormatImporter.java:91)
        at java.base/java.util.ArrayList.forEach(Unknown Source)
        at org.sonar.go.externalreport.GolangCILintReportSensor.execute(GolangCILintReportSensor.java:49)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)

INFO: Sensor Import of GolangCI-Lint issues [go] (done) | time=26ms

The file it is analyzing looks like this (where I can see some white space being created at the top of the file):





<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0"><file name="members/apistore_test.go"><error column="6" line="516" message="func `setupTestMember` is unused" severity="error" source="unused"></error><error column="3" line="242" message="field `groupUUID` is unused" severity="error" source="unused"></error><error column="23" line="519" message="Error return value of `client.PerformRequest` is not checked" severity="error" source="errcheck"></error><error column="15" line="48" message="ineffectual assignment to `pherr`" severity="error" source="ineffassign"></error></file><file name="processor/datastore_mock.go"><error column="6" line="10" message="type `datastoreMock` is unused" severity="error" source="unused"></error></file><file name="queue/queue.go"><error column="13" line="28" message="SA1019: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made. " severity="error" source="staticcheck"></error><error column="4" line="95" message="S1023: redundant `return` statement" severity="error" source="gosimple"></error></file><file name="members/members.go"><error column="7" line="17" message="const `attrNameGroupAltID` is unused" severity="error" source="unused"></error><error column="7" line="16" message="const `attrNameMemberAltID` is unused" severity="error" source="unused"></error><error column="7" line="14" message="const `errorNoMemberAltID` is unused" severity="error" source="unused"></error><error column="5" line="95" message="S1023: redundant break statement" severity="error" source="gosimple"></error><error column="5" line="98" message="S1023: redundant break statement" severity="error" source="gosimple"></error></file></checkstyle>

Hi Cameron,

The xml file content looks fine, my SonarGo is able to parse it without WstxParsingException. Could you confirm that it’s really this file that you import using the property sonar.go.golangci-lint.reportPaths? Which JVM do you use?

I didn’t notice but your xml report does not start with <?xml but there’s some spaces before :scream:.
By adding spaces before <?xml in an xml report, I’m able to reproduce the com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs. at [row,col {unknown-source}]: [5,5]
But it makes sense because it’s not a valid xml. Why do you have those spaces?

1 Like

I can’t honestly say where those spaces came from, though I did find an issue with how I was executing the golangci-lint command that was causing issues when executing it from my script and after fixing that issue this is no longer happening. I made a few changes over the course of the evening, so bear with me and I’ll outline the things I had to touch to get it working smoothly:

  1. I was running the linter from the Docker container golangci/golangci-lint using a command like this: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.23.3 golangci-lint run -v
    The problem with this was that we have some packages being imported from private repos and so I was getting some errors like: could not determine GOARCH and Go compiler with some other xml content preceding and following. To resolve this I pulled the binary for the golangci-lint and built it into a docker container that we use for running the rest of our Go build and test operations.
  2. The second mistake I found (and perhaps the one that was causing the white space in the files) was that in my troubleshooting I’d added a -ti into my docker run command to get an interactive terminal. Perhaps when I was running my command manually it added white space into the beginning of the file? Either way when running this command from a script in my Jenkins build you get an error about no terminal and a blank 0B file:
docker run --rm -ti\
    -v "${PWD}:/go/src/app" \
    -w "/go/src/app" \
    <repo>/go-build \
    golangci-lint run ./... --verbose --no-config --out-format checkstyle > golangci-lint.out`.  

This command was modified to the following, which appears to work properly:

docker run --rm \
    -v "${PWD}:/go/src/app" \
    -w "/go/src/app" \
    <repo>/go-build \
    golangci-lint run ./... --verbose --no-config --out-format checkstyle > golangci-lint.out

So I’m working now and all appears to be fine. Thank you for your response and confirmation that the white space was causing the issue!