StefanRRichter commented on a change in pull request #7273: [FLINK-11122][core]
Change signature of WrappingProxyUtil#stripProxy(T)
URL: https://github.com/apache/flink/pull/7273#discussion_r240538098
##########
File path:
flink-core/src/main/java/org/apache/flink/util/WrappingProxyUtil.java
##########
@@ -31,15 +33,19 @@ private WrappingProxyUtil() {
}
@SuppressWarnings("unchecked")
- public static <T> T stripProxy(T object) {
+ public static <T> T stripProxy(@Nullable final WrappingProxy<T>
wrappingProxy) {
+ if (wrappingProxy == null) {
+ return null;
+ }
- T previous = null;
+ WrappingProxy<T> previous = null;
+ Object delegate = wrappingProxy.getWrappedDelegate();
- while (object instanceof WrappingProxy && previous != object) {
- previous = object;
- object = ((WrappingProxy<T>)
object).getWrappedDelegate();
+ while (delegate instanceof WrappingProxy && previous !=
delegate) {
+ previous = (WrappingProxy<T>) delegate;
+ delegate = ((WrappingProxy<T>)
delegate).getWrappedDelegate();
Review comment:
I think casting to `(WrappingProxy<T>)` here is problematic because the
getter will already implicitly cast the returned object to `T` and you are in
the cast exception that the rest of the code tries to avoid now. I suggest
maybe rather this:
```
Object previous = null;
Object delegate = wrappingProxy.getWrappedDelegate();
while (delegate instanceof WrappingProxy && previous !=
delegate) {
previous = delegate;
delegate = ((WrappingProxy<?>)
delegate).getWrappedDelegate();
}
return (T) delegate;
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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