Skip to content

Commit

Permalink
Handle missing methods on ChannelHandlerMask (netty#9221)
Browse files Browse the repository at this point in the history
Motivation:

When Netty is run through ProGuard, seemingly unused methods are removed.  This breaks reflection, making the Handler skipping throw a reflective error.

Modification:

If a method is seemingly absent, just disable the optimization.

Result:

Dealing with ProGuard sucks infinitesimally less.
  • Loading branch information
carl-mastrangelo authored and normanmaurer committed Jun 7, 2019
1 parent 643d521 commit 67ad79d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion transport/src/main/java/io/netty/channel/ChannelHandlerMask.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.internal.PlatformDependent;

import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.net.SocketAddress;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.Map;
import java.util.WeakHashMap;

final class ChannelHandlerMask {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ChannelHandlerMask.class);

// Using to mask which methods must be called for a ChannelHandler.
static final int MASK_EXCEPTION_CAUGHT = 1;
Expand Down Expand Up @@ -163,7 +167,15 @@ private static boolean isSkippable(
return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
@Override
public Boolean run() throws Exception {
return handlerType.getMethod(methodName, paramTypes).isAnnotationPresent(Skip.class);
Method m;
try {
m = handlerType.getMethod(methodName, paramTypes);
} catch (NoSuchMethodException e) {
logger.debug(
"Class {} missing method {}, assume we can not skip execution", handlerType, methodName, e);
return false;
}
return m.isAnnotationPresent(Skip.class);
}
});
}
Expand Down

0 comments on commit 67ad79d

Please sign in to comment.