Skip to content

Commit

Permalink
Exception are a bit different when Epoll is used.
Browse files Browse the repository at this point in the history
Adapt port bind exception to wrap any possible exception that happened
during bind operation.
  • Loading branch information
MishaDemianenko committed Sep 15, 2017
1 parent b4e718d commit c6d2795
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
Expand Up @@ -27,7 +27,6 @@
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.Epoll;

import java.net.BindException;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -116,12 +115,7 @@ public void start() throws Throwable
// We catch throwable here because netty uses clever tricks to have method signatures that look like they do not
// throw checked exceptions, but they actually do. The compiler won't let us catch them explicitly because in theory
// they shouldn't be possible, so we have to catch Throwable and do our own checks to grab them

if ( e instanceof BindException )
{
throw new PortBindException( bootstrapEntry.getValue().address(), (BindException) e );
}
throw e;
throw new PortBindException( bootstrapEntry.getValue().address(), e );
}
}
}
Expand Down
Expand Up @@ -54,7 +54,6 @@ public void shouldGivePortConflictErrorWithPortNumberInIt() throws Throwable

// Expect
exception.expect( PortBindException.class );
exception.expectMessage( "Address localhost:16000 is already in use" );

// When
Map<BoltConnector,NettyServer.ProtocolInitializer> initializersMap =
Expand Down
Expand Up @@ -28,13 +28,13 @@
*/
public class PortBindException extends BindException
{
public PortBindException( ListenSocketAddress address, BindException original )
public PortBindException( ListenSocketAddress address, Throwable original )
{
super( String.format("Address %s is already in use, cannot bind to it.", address) );
setStackTrace( original.getStackTrace() );
}

public PortBindException( ListenSocketAddress address, ListenSocketAddress other, BindException original )
public PortBindException( ListenSocketAddress address, ListenSocketAddress other, Throwable original )
{
super( String.format("At least one of the addresses %s or %s is already in use, cannot bind to it.", address, other) );
setStackTrace( original.getStackTrace() );
Expand Down

0 comments on commit c6d2795

Please sign in to comment.