com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl的Java 11 UTF-16 BOM问题

时间:2019-04-01 06:13:15

标签: jaxb utf-16 moxy java-11 xerces

我有一个UTF-16 XML文件:

<?xml version="1.0" encoding="utf-16" standalone="yes"?>

以BOM FE FF开头。

将我的代码迁移到Java 11,我得到:

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652) ~[?:?]

这是使用JAXB解组的。

是否使用参考实现会发生这种情况:

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652) ~[?:?]
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:134) ~[jaxb-runtime-2.4.0-SNAPSHOT.jar:?]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:385) ~[jaxb-runtime-2.4.0-SNAPSHOT.jar:?]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:356) ~[jaxb-runtime-2.4.0-SNAPSHOT.jar:?]

或MOXy:

Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652) ~[?:?]
    at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:98) ~[org.eclipse.persistence.core-2.5.2.jar:?]
    at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:86) ~[org.eclipse.persistence.core-2.5.2.jar:?]
    at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:895) ~[org.eclipse.persistence.core-2.5.2.jar:?]
    at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:659) ~[org.eclipse.persistence.core-2.5.2.jar:?]
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:585) ~[org.eclipse.persistence.moxy-2.5.2.jar:?]

它们都使用com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl

使用Java 6到8对该文件进行解组工作正常,在Java 9或11中是否发生了某些变化?

如果我删除FE FF BOM,它将在Java 11中解封OK。

1 个答案:

答案 0 :(得分:0)

原来我的问题是由maven-resources-plugin引起的,过滤设置为true。那就是在处理所有UTF-16资源,将前2个字节更改为EF BF。