Skip to content

Commit

Permalink
AbstractMethodError with barchart-udt
Browse files Browse the repository at this point in the history
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 [netty#6934].
  • Loading branch information
fenik17 authored and normanmaurer committed Jul 5, 2017
1 parent 91b62da commit 1ba265a
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
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.*;
Expand Down Expand Up @@ -98,7 +102,7 @@ public UdtChannelConfig config() {

@Override
protected void doBind(final SocketAddress localAddress) throws Exception {
SocketUtils.bind(javaChannel(), localAddress);
privilegedBind(javaChannel(), localAddress);
}

@Override
Expand Down Expand Up @@ -233,4 +237,19 @@ public InetSocketAddress localAddress() {
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();
}
}
}

0 comments on commit 1ba265a

Please sign in to comment.