ppkarwasz commented on PR #784:
URL: https://github.com/apache/commons-io/pull/784#issuecomment-3320646816

   > > Resource ownership semantics are unclear. Some origins wrap pre-opened 
resources (InputStream, RandomAccessFile, Channel), others create new resources 
on demand (byte[], File, Path, URI). Right now it’s ambiguous who “owns” the 
underlying resource. In practice, the builder should not take ownership unless 
explicitly documented; otherwise returned resources should be close-shielded.
   > 
   > I thought this was all clear to: The allocator owns the resources and must 
close it.
   > 
   > Are there any bugs?
   
   If the intent is that the allocator always owns and closes the resource, 
then we do have a problem: the current implementations don’t consistently 
enforce that contract. For example, resources returned from `AbstractOrigin` 
are not close-shielded, so callers can unintentionally close the underlying 
origin.
   
   A concrete case:
   
   ```java
   InputStream original = ...
   InputStreamOrigin origin = new InputStreamOrigin(original);
   try (InputStream input = origin.getInputStream()) {
     // Do something
   }
   // original is closed unexpectedly
   ```
   
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to