ppkarwasz commented on code in PR #799:
URL: https://github.com/apache/commons-io/pull/799#discussion_r2430022932
##########
src/main/java/org/apache/commons/io/channels/CloseShieldChannel.java:
##########
@@ -66,10 +69,32 @@ public static <T extends Channel> T wrap(final T channel) {
// Collect only Channel sub-interfaces.
final Set<Class<?>> set = collectChannelInterfaces(channel.getClass(),
new LinkedHashSet<>());
// fallback to root surface
- return (T) Proxy.newProxyInstance(channel.getClass().getClassLoader(),
// use delegate's loader
+ return (Channel)
Proxy.newProxyInstance(channel.getClass().getClassLoader(), // use delegate's
loader
set.isEmpty() ? new Class<?>[] { Channel.class } :
set.toArray(EMPTY), new CloseShieldChannelHandler(channel));
}
+ /**
+ * Wraps a channel to shield it from being closed.
Review Comment:
Yes, initially I devised this API for cases like `FileChannel`,
`DatagramChannel`, `SocketChannel`, `SelectableChannel` and
`ServerSocketChannel`. These are all classes (not interfaces), so the user
**needs** to cast the result of `wrap` to an **interface**. I introduced this
method to force the user to make an explicit cast.
I am not really sure this is the best approach. In
https://github.com/apache/commons-io/pull/799/commits/7a0608f5b755e989930add275e3376d27cdb098c
I tried replacing this method with some overloads for common interfaces.
--
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]