我写了一个unmarshal方法,可以通过一系列并行运行的测试来访问这些方法来读取XML文件中的数据。
此方法位于添加到主模块的maven commons依赖模块中。 我面临java.io.IOException:以非常不一致的方式流关闭异常,并且无法在本地重现它。只有当我的测试在Jenkins的CI中运行时才会发生,而且这种情况也不常发生。代码如下。
public <T> Object internalUnmarshal(String url, Class<T> clazz)
throws JAXBException,DataException, ClassNotFoundException,IOException
{
InputStream is = getClass().getResourceAsStream(url);
try {
if (is == null) {
throw new DataException("''{0}'' not found.", url);
}
JAXBContext jaxbContext = JAXBContext
.newInstance(Class.forName(clazz.getCanonicalName());
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return unmarshaller.unmarshal(is);
} catch (JAXBException e) {
throw new JAXBException(e);
} finally {
is.close();
}
}
我甚至在下面添加了一个synchronized块,但在jenkins服务器运行中再现了同样的问题。
synchronized(this){
return unmarshaller.unmarshal(is);
}
下面的堆栈跟踪: -
[javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.IOException: Stream closed]]
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.internalUnmarshal(XMLUnmarshaler.java:116)
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.resloveToUnmarshaledObjectList(XMLUnmarshaler.java:76)
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.doUnmarshalObjects(XMLUnmarshaler.java:36)
... 67 more
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.IOException: Stream closed]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:261)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:229)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:204)
at com.paydiant.commons.data.unmarshalers.XMLUnmarshaler.internalUnmarshal(XMLUnmarshaler.java:112)
... 69 more
Caused by: java.io.IOException: Stream closed
at java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:67)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:121)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:258)
... 73 more
任何可能导致此问题的想法?