由于 "Failed to parse xml report":"An invalid XML character (Unicode: 0xffff) was found in the CDATA section.",TeamCity 构建失败

TeamCity build failed because of "Failed to parse xml report": "An invalid XML character (Unicode: 0xffff) was found in the CDATA section."

如何解决生成日志中的以下 TeamCity 错误?构建失败并显示“无法解析 xml 报告”。

[Surefire report watcher] Parsing errors
[00:34:17]  [Parsing errors] Failed to parse 1 report
[00:34:17]  [Parsing errors] rose/target/surefire-reports/TEST-TestSuite.xml: An invalid XML character (Unicode: 0xffff) was found in the CDATA section.
[00:34:17]  [Parsing errors] jetbrains.buildServer.util.XmlXppAbstractParser: An invalid XML character (Unicode: 0xffff) was found in the CDATA section.
    at jetbrains.buildServer.util.XmlXppAbstractParser.parse(XmlXppAbstractParser.java:39)
    at jetbrains.buildServer.util.XmlXppAbstractParser.parse(XmlXppAbstractParser.java:31)
    at jetbrains.buildServer.xmlReportPlugin.parsers.antJUnit.AntJUnitReportParser.parse(AntJUnitReportParser.java:179)
    at jetbrains.buildServer.xmlReportPlugin.ParseReportCommand.run(ParseReportCommand.java:62)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1489; columnNumber: 74; An invalid XML character (Unicode: 0xffff) was found in the CDATA section.
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at jetbrains.buildServer.util.XmlXppAbstractParser.parseWithSAX(XmlXppAbstractParser.java:240)
    at jetbrains.buildServer.util.XmlXppAbstractParser.parse(XmlXppAbstractParser.java:37)
    ... 8 more

XML文件(另存为神器)在Notepad++中可以正常打开,但在Chrome中点击打开时出现以下错误:

This page contains the following errors:
error on line 86 at column 18: Input is not proper UTF-8, indicate encoding !
Bytes: 0xEF 0xBF 0xBF 0x0A

如果有帮助,问题似乎是在 之后引起的。

事实证明 0xffff 字符实际上是在代码中生成的,因为它在某处被保存为常量。对于未来的读者,我建议在您的代码中搜索 \uffff 并避免在测试中打印它。