You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2021/02/22 13:04:38 UTC

[GitHub] [cxf] reta commented on a change in pull request #748: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava (targeting StAX's XMLStreamReader)

reta commented on a change in pull request #748:
URL: https://github.com/apache/cxf/pull/748#discussion_r580233404



##########
File path: core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
##########
@@ -1660,22 +1667,38 @@ public static XMLStreamReader createXMLStreamReader(InputSource src) {
         String sysId = src.getSystemId() == null ? null : src.getSystemId();
         String pubId = src.getPublicId() == null ? null : src.getPublicId();
         if (src.getByteStream() != null) {
+            final InputStream is = src.getByteStream();
+
             if (src.getEncoding() == null) {
-                StreamSource ss = new StreamSource(src.getByteStream(), sysId);
+                final StreamSource ss = new StreamSource(is, sysId);
                 ss.setPublicId(pubId);
-                return createXMLStreamReader(ss);
+                
+                final XMLStreamReader xmlStreamReader = createXMLStreamReader(ss);
+                if (AUTO_CLOSE_INPUT_SOURCE) {
+                    return new AutoCloseableXMLStreamReader(xmlStreamReader, is);

Review comment:
       That is correct (unless typecasted) but the value here is in how `AutoCloseableXMLStreamReader` defines `close` method: closing the reader and input stream. In my initial attempt, the `AutoCloseableXMLStreamReader` was promoted to return value (covering try-with-resources) but the consequences of closing the `InputSource` streams all the time are not clear to me. It could break things easily.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org