Cleanup EPOLL native exceptions

Motivation:
Exceptions generated from transport-native-epoll may include duplicate error string description or inconsistent usage of the method name in the string description.

Modifications:
- Ensure the method name from static exceptions and dynamic exceptions is of the same format
- Remove duplicate string rational from the exception messages

Result:
More consistent error messages with no duplicate error description.
This commit is contained in:
Scott Mitchell 2017-03-01 04:00:35 -08:00
parent df6796153b
commit 93f5f62a20
3 changed files with 38 additions and 38 deletions

View File

@ -61,7 +61,7 @@ public final class Errors {
private static final long serialVersionUID = 8222160204268655526L; private static final long serialVersionUID = 8222160204268655526L;
private final int expectedErr; private final int expectedErr;
public NativeIoException(String method, int expectedErr) { public NativeIoException(String method, int expectedErr) {
super(method + " failed: " + ERRORS[-expectedErr]); super(method + "(..) failed: " + ERRORS[-expectedErr]);
this.expectedErr = expectedErr; this.expectedErr = expectedErr;
} }
@ -74,7 +74,7 @@ public final class Errors {
private static final long serialVersionUID = -5532328671712318161L; private static final long serialVersionUID = -5532328671712318161L;
private final int expectedErr; private final int expectedErr;
NativeConnectException(String method, int expectedErr) { NativeConnectException(String method, int expectedErr) {
super(method + " failed: " + ERRORS[-expectedErr]); super(method + "(..) failed: " + ERRORS[-expectedErr]);
this.expectedErr = expectedErr; this.expectedErr = expectedErr;
} }
@ -104,7 +104,7 @@ public final class Errors {
if (err == ERROR_EISCONN_NEGATIVE) { if (err == ERROR_EISCONN_NEGATIVE) {
throw new AlreadyConnectedException(); throw new AlreadyConnectedException();
} }
throw new ConnectException(method + "() failed: " + ERRORS[-err]); throw new ConnectException(method + "(..) failed: " + ERRORS[-err]);
} }
public static NativeIoException newConnectionResetException(String method, int errnoNegative) { public static NativeIoException newConnectionResetException(String method, int errnoNegative) {
@ -114,7 +114,7 @@ public final class Errors {
} }
public static NativeIoException newIOException(String method, int err) { public static NativeIoException newIOException(String method, int err) {
return new NativeIoException(method + "() failed: " + ERRORS[-err], err); return new NativeIoException(method, err);
} }
public static int ioResult(String method, int err, NativeIoException resetCause, public static int ioResult(String method, int err, NativeIoException resetCause,

View File

@ -33,35 +33,35 @@ import static io.netty.util.internal.ObjectUtil.checkNotNull;
*/ */
public class FileDescriptor { public class FileDescriptor {
private static final ClosedChannelException WRITE_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final ClosedChannelException WRITE_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace(
new ClosedChannelException(), FileDescriptor.class, "write(...)"); new ClosedChannelException(), FileDescriptor.class, "write(..)");
private static final ClosedChannelException WRITE_ADDRESS_CLOSED_CHANNEL_EXCEPTION = private static final ClosedChannelException WRITE_ADDRESS_CLOSED_CHANNEL_EXCEPTION =
ThrowableUtil.unknownStackTrace(new ClosedChannelException(), FileDescriptor.class, "writeAddress(...)"); ThrowableUtil.unknownStackTrace(new ClosedChannelException(), FileDescriptor.class, "writeAddress(..)");
private static final ClosedChannelException WRITEV_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final ClosedChannelException WRITEV_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace(
new ClosedChannelException(), FileDescriptor.class, "writev(...)"); new ClosedChannelException(), FileDescriptor.class, "writev(..)");
private static final ClosedChannelException WRITEV_ADDRESSES_CLOSED_CHANNEL_EXCEPTION = private static final ClosedChannelException WRITEV_ADDRESSES_CLOSED_CHANNEL_EXCEPTION =
ThrowableUtil.unknownStackTrace(new ClosedChannelException(), FileDescriptor.class, "writevAddresses(...)"); ThrowableUtil.unknownStackTrace(new ClosedChannelException(), FileDescriptor.class, "writevAddresses(..)");
private static final ClosedChannelException READ_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final ClosedChannelException READ_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace(
new ClosedChannelException(), FileDescriptor.class, "read(...)"); new ClosedChannelException(), FileDescriptor.class, "read(..)");
private static final ClosedChannelException READ_ADDRESS_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final ClosedChannelException READ_ADDRESS_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace(
new ClosedChannelException(), FileDescriptor.class, "readAddress(...)"); new ClosedChannelException(), FileDescriptor.class, "readAddress(..)");
private static final Errors.NativeIoException WRITE_CONNECTION_RESET_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final Errors.NativeIoException WRITE_CONNECTION_RESET_EXCEPTION = ThrowableUtil.unknownStackTrace(
Errors.newConnectionResetException("syscall:write(...)", Errors.ERRNO_EPIPE_NEGATIVE), Errors.newConnectionResetException("syscall:write", Errors.ERRNO_EPIPE_NEGATIVE),
FileDescriptor.class, "write(...)"); FileDescriptor.class, "write(..)");
private static final Errors.NativeIoException WRITE_ADDRESS_CONNECTION_RESET_EXCEPTION = private static final Errors.NativeIoException WRITE_ADDRESS_CONNECTION_RESET_EXCEPTION =
ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:write(...)", ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:write",
Errors.ERRNO_EPIPE_NEGATIVE), FileDescriptor.class, "writeAddress(...)"); Errors.ERRNO_EPIPE_NEGATIVE), FileDescriptor.class, "writeAddress(..)");
private static final Errors.NativeIoException WRITEV_CONNECTION_RESET_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final Errors.NativeIoException WRITEV_CONNECTION_RESET_EXCEPTION = ThrowableUtil.unknownStackTrace(
Errors.newConnectionResetException("syscall:writev(...)", Errors.ERRNO_EPIPE_NEGATIVE), Errors.newConnectionResetException("syscall:writev", Errors.ERRNO_EPIPE_NEGATIVE),
FileDescriptor.class, "writev(...)"); FileDescriptor.class, "writev(..)");
private static final Errors.NativeIoException WRITEV_ADDRESSES_CONNECTION_RESET_EXCEPTION = private static final Errors.NativeIoException WRITEV_ADDRESSES_CONNECTION_RESET_EXCEPTION =
ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:writev(...)", ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:writev",
Errors.ERRNO_EPIPE_NEGATIVE), FileDescriptor.class, "writeAddresses(...)"); Errors.ERRNO_EPIPE_NEGATIVE), FileDescriptor.class, "writeAddresses(..)");
private static final Errors.NativeIoException READ_CONNECTION_RESET_EXCEPTION = ThrowableUtil.unknownStackTrace( private static final Errors.NativeIoException READ_CONNECTION_RESET_EXCEPTION = ThrowableUtil.unknownStackTrace(
Errors.newConnectionResetException("syscall:read(...)", Errors.ERRNO_ECONNRESET_NEGATIVE), Errors.newConnectionResetException("syscall:read", Errors.ERRNO_ECONNRESET_NEGATIVE),
FileDescriptor.class, "read(...)"); FileDescriptor.class, "read(..)");
private static final Errors.NativeIoException READ_ADDRESS_CONNECTION_RESET_EXCEPTION = private static final Errors.NativeIoException READ_ADDRESS_CONNECTION_RESET_EXCEPTION =
ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:read(...)", ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:read",
Errors.ERRNO_ECONNRESET_NEGATIVE), FileDescriptor.class, "readAddress(...)"); Errors.ERRNO_ECONNRESET_NEGATIVE), FileDescriptor.class, "readAddress(..)");
private static final AtomicIntegerFieldUpdater<FileDescriptor> stateUpdater = private static final AtomicIntegerFieldUpdater<FileDescriptor> stateUpdater =
AtomicIntegerFieldUpdater.newUpdater(FileDescriptor.class, "state"); AtomicIntegerFieldUpdater.newUpdater(FileDescriptor.class, "state");

View File

@ -42,31 +42,31 @@ import static io.netty.util.internal.ThrowableUtil.unknownStackTrace;
*/ */
public final class Socket extends FileDescriptor { public final class Socket extends FileDescriptor {
private static final ClosedChannelException SHUTDOWN_CLOSED_CHANNEL_EXCEPTION = unknownStackTrace( private static final ClosedChannelException SHUTDOWN_CLOSED_CHANNEL_EXCEPTION = unknownStackTrace(
new ClosedChannelException(), Socket.class, "shutdown(...)"); new ClosedChannelException(), Socket.class, "shutdown(..)");
private static final ClosedChannelException SEND_TO_CLOSED_CHANNEL_EXCEPTION = unknownStackTrace( private static final ClosedChannelException SEND_TO_CLOSED_CHANNEL_EXCEPTION = unknownStackTrace(
new ClosedChannelException(), Socket.class, "sendTo(...)"); new ClosedChannelException(), Socket.class, "sendTo(..)");
private static final ClosedChannelException SEND_TO_ADDRESS_CLOSED_CHANNEL_EXCEPTION = private static final ClosedChannelException SEND_TO_ADDRESS_CLOSED_CHANNEL_EXCEPTION =
unknownStackTrace(new ClosedChannelException(), Socket.class, "sendToAddress(...)"); unknownStackTrace(new ClosedChannelException(), Socket.class, "sendToAddress(..)");
private static final ClosedChannelException SEND_TO_ADDRESSES_CLOSED_CHANNEL_EXCEPTION = private static final ClosedChannelException SEND_TO_ADDRESSES_CLOSED_CHANNEL_EXCEPTION =
unknownStackTrace(new ClosedChannelException(), Socket.class, "sendToAddresses(...)"); unknownStackTrace(new ClosedChannelException(), Socket.class, "sendToAddresses(..)");
private static final Errors.NativeIoException SEND_TO_CONNECTION_RESET_EXCEPTION = unknownStackTrace( private static final Errors.NativeIoException SEND_TO_CONNECTION_RESET_EXCEPTION = unknownStackTrace(
Errors.newConnectionResetException("syscall:sendto(...)", Errors.ERRNO_EPIPE_NEGATIVE), Errors.newConnectionResetException("syscall:sendto", Errors.ERRNO_EPIPE_NEGATIVE),
Socket.class, "sendTo(...)"); Socket.class, "sendTo(..)");
private static final Errors.NativeIoException SEND_TO_ADDRESS_CONNECTION_RESET_EXCEPTION = private static final Errors.NativeIoException SEND_TO_ADDRESS_CONNECTION_RESET_EXCEPTION =
unknownStackTrace(Errors.newConnectionResetException("syscall:sendto(...)", unknownStackTrace(Errors.newConnectionResetException("syscall:sendto",
Errors.ERRNO_EPIPE_NEGATIVE), Socket.class, "sendToAddress(...)"); Errors.ERRNO_EPIPE_NEGATIVE), Socket.class, "sendToAddress");
private static final Errors.NativeIoException CONNECTION_RESET_EXCEPTION_SENDMSG = unknownStackTrace( private static final Errors.NativeIoException CONNECTION_RESET_EXCEPTION_SENDMSG = unknownStackTrace(
Errors.newConnectionResetException("syscall:sendmsg(...)", Errors.newConnectionResetException("syscall:sendmsg",
Errors.ERRNO_EPIPE_NEGATIVE), Socket.class, "sendToAddresses(...)"); Errors.ERRNO_EPIPE_NEGATIVE), Socket.class, "sendToAddresses(..)");
private static final Errors.NativeIoException CONNECTION_RESET_SHUTDOWN_EXCEPTION = private static final Errors.NativeIoException CONNECTION_RESET_SHUTDOWN_EXCEPTION =
unknownStackTrace(Errors.newConnectionResetException("syscall:shutdown(...)", unknownStackTrace(Errors.newConnectionResetException("syscall:shutdown",
Errors.ERRNO_ECONNRESET_NEGATIVE), Socket.class, "shutdown(...)"); Errors.ERRNO_ECONNRESET_NEGATIVE), Socket.class, "shutdown");
private static final Errors.NativeConnectException FINISH_CONNECT_REFUSED_EXCEPTION = private static final Errors.NativeConnectException FINISH_CONNECT_REFUSED_EXCEPTION =
unknownStackTrace(new Errors.NativeConnectException("syscall:getsockopt(...)", unknownStackTrace(new Errors.NativeConnectException("syscall:getsockopt",
Errors.ERROR_ECONNREFUSED_NEGATIVE), Socket.class, "finishConnect(...)"); Errors.ERROR_ECONNREFUSED_NEGATIVE), Socket.class, "finishConnect(..)");
private static final Errors.NativeConnectException CONNECT_REFUSED_EXCEPTION = private static final Errors.NativeConnectException CONNECT_REFUSED_EXCEPTION =
unknownStackTrace(new Errors.NativeConnectException("syscall:connect(...)", unknownStackTrace(new Errors.NativeConnectException("syscall:connect",
Errors.ERROR_ECONNREFUSED_NEGATIVE), Socket.class, "connect(...)"); Errors.ERROR_ECONNREFUSED_NEGATIVE), Socket.class, "connect(..)");
public Socket(int fd) { public Socket(int fd) {
super(fd); super(fd);
} }