stevedlawrence commented on a change in pull request #219: Ensure InputStreams 
created by includes/imports are closed
URL: https://github.com/apache/incubator-daffodil/pull/219#discussion_r284830717
 
 

 ##########
 File path: 
daffodil-lib/src/main/scala/org/apache/daffodil/xml/DaffodilXMLLoader.scala
 ##########
 @@ -463,9 +462,11 @@ trait SchemaAwareLoaderMixin {
    * it a plain old file or resource, and not try to play games to get it to
    * pick up the file/line/col information from attributes of the elements.
    */
-  def validateSchema(source: DaffodilSchemaSource) = {
-    val saxSource = new SAXSource(source.newInputSource())
+  def validateSchema(source: DaffodilSchemaSource): Unit = {
+    val inputSource = source.newInputSource()
+    val saxSource = new SAXSource(inputSource)
     sf.newSchema(saxSource)
+    inputSource.getByteStream().close()
 
 Review comment:
   When Xerces comes across an include/import it calls into our resolver to get 
an LSInput to the resource. We don't currently keep track of the InputStreams 
we open to give back to Xerces, and there isn't an easy way to get access to 
Xerces handles of those InputStreams.
   
   So if we wanted to assert they were all closed, I think we'd need to change 
our DFDLCatalogResolver to keep track of all the LSInputs that it gives Xerces 
in some state, and then at the end of validation we could confirm that all the 
LSInputs we created were properly closed. But that introduces state, and 
there's a handful of places where catalog resolvers are used so I'm not sure 
this is a trival change. And I don't think there's even a good way to tell if 
an InputStream is closed. Looks like the best you can do is try to read from 
the InputSource and catch an exception. Seems like a bit of a headache just to 
make sure Xerces is doing the right thing.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to