AbstractMethodError with barchart-udt

Motivation:

`SocketChannelUDT` from barchart-udt does not have the java 7 `public abstract SocketChannel bind(SocketAddress local)` method. Calling the abstract method `SocketChannel.bind(SocketAddress localAddress)` for `SocketChannelUDT` leads to an `AbstractMethodError` runtime error.

Modifications:

Make workaround with explicit call of `SocketChannelUDT.bind(SocketAddress local)` as it done in `NioUdtByteConnectorChannel`.

Result:

Fixes [#6934].
This commit is contained in:
Nikolay Fedorovskikh 2017-07-05 03:25:16 +05:00 committed by Norman Maurer
parent e9cf960cba
commit 0a6df7b764

View File

@ -32,8 +32,12 @@ import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.List;
import static java.nio.channels.SelectionKey.*;
@ -100,7 +104,7 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel imp
@Override
protected void doBind(final SocketAddress localAddress) throws Exception {
SocketUtils.bind(javaChannel(), localAddress);
privilegedBind(javaChannel(), localAddress);
}
@Override
@ -245,4 +249,19 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel imp
public InetSocketAddress remoteAddress() {
return (InetSocketAddress) super.remoteAddress();
}
private static void privilegedBind(final SocketChannelUDT socketChannel, final SocketAddress localAddress)
throws IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws IOException {
socketChannel.bind(localAddress);
return null;
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getCause();
}
}
}