ppkarwasz opened a new pull request, #799:
URL: https://github.com/apache/commons-io/pull/799

   Two bugs in the `CloseShieldChannel` helper make it unreliable in practice:
   
   1. **Type-erasure bug in `T wrap(T)`** The method signature only works 
correctly when `T` is an **interface** extending `Channel`. Since Java’s type 
system doesn’t allow constraining `T` to “interface types only,” this could 
lead to unexpected runtime `ClassCastException`s even though the code compiles 
successfully.
   
   2. **Incomplete interface discovery** The implementation only inspected 
interfaces **directly** implemented by the given channel’s class, ignoring 
those inherited from its superclasses. As a result, proxies for types such as 
`FileChannel` did not expose any of the interfaces declared on `FileChannel` 
itself.
   
   #### Fixes
   
   This PR addresses both issues:
   
   * **Reworks the API signature**
   
     * Replaces `T wrap(T)` with its erasure: `Channel wrap(Channel)`.
     * Introduces a new overload: `T wrap(T, Class<T>)`, which allows callers 
to explicitly specify the interface type they expect. This version fails fast 
with a clear `IllegalArgumentException` if the provided type is not an 
interface, instead of allowing a `ClassCastException` later.
   
   * **Improves interface collection logic**
   
     * Updates the implementation to include interfaces declared on 
superclasses, ensuring all relevant `Channel` interfaces are correctly proxied.
   


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