From 6aa30b2b6e6a69f718da04d753e643ac418a4c9d Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 11 Aug 2020 16:04:15 +0200 Subject: [PATCH] Fix invokeExact(...) usage in JdkAlpnSslUtils (#10471) Motivation: fd0d06e introduced the usage of MethodHandles and so also introduced some usages of invokeExact(...). Unfortunally when calling this method we missed to also cast the return value in the static init block of JdkAlpnSslUtils which lead to an exception to be thrown as the JVM did assume the return value is void which is not true. Modifications: Correctly cast the return value of invokeExact(...) Result: ALPN can be used in master with JDK again --- .../java/io/netty/handler/ssl/JdkAlpnSslUtils.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslUtils.java b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslUtils.java index b672106ed3..3e2cad728f 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslUtils.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslUtils.java @@ -56,12 +56,14 @@ final class JdkAlpnSslUtils { AccessController.doPrivileged((PrivilegedExceptionAction) () -> lookup.findVirtual(SSLEngine.class, "getHandshakeApplicationProtocol", MethodType.methodType(String.class))); - getHandshakeApplicationProtocol.invokeExact(engine); + // Invoke and specify the return type so the compiler doesnt try to use void + String getHandshakeApplicationProtocolRes = (String) getHandshakeApplicationProtocol.invokeExact(engine); getApplicationProtocol = AccessController.doPrivileged((PrivilegedExceptionAction) () -> lookup.findVirtual(SSLEngine.class, "getApplicationProtocol", MethodType.methodType(String.class))); - getApplicationProtocol.invokeExact(engine); + // Invoke and specify the return type so the compiler doesnt try to use void + String getApplicationProtocolRes = (String) getApplicationProtocol.invokeExact(engine); setApplicationProtocols = AccessController.doPrivileged((PrivilegedExceptionAction) () -> lookup.findVirtual(SSLParameters.class, "setApplicationProtocols", @@ -79,7 +81,11 @@ final class JdkAlpnSslUtils { AccessController.doPrivileged((PrivilegedExceptionAction) () -> lookup.findVirtual(SSLEngine.class, "getHandshakeApplicationProtocolSelector", MethodType.methodType(BiFunction.class))); - getHandshakeApplicationProtocolSelector.invokeExact(engine); + // Invoke and specify the return type so the compiler doesnt try to use void + @SuppressWarnings("unchecked") + BiFunction, String> getHandshakeApplicationProtocolSelectorRes = + (BiFunction, String>) + getHandshakeApplicationProtocolSelector.invokeExact(engine); } catch (Throwable t) { int version = PlatformDependent.javaVersion(); if (version >= 9) {