diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostStandardRequestDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostStandardRequestDecoder.java index 8bce1c4a93..f527b104f6 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostStandardRequestDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostStandardRequestDecoder.java @@ -599,11 +599,7 @@ public class HttpPostStandardRequestDecoder implements InterfaceHttpPostRequestD // error while decoding undecodedChunk.readerIndex(firstpos); throw e; - } catch (IOException e) { - // error while decoding - undecodedChunk.readerIndex(firstpos); - throw new ErrorDataDecoderException(e); - } catch (IllegalArgumentException e) { + } catch (IOException | IllegalArgumentException e) { // error while decoding undecodedChunk.readerIndex(firstpos); throw new ErrorDataDecoderException(e); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java index 2d78fc9ca9..57ad0f81b6 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java @@ -235,14 +235,7 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder { // immediately processed. bytesToReturn = listener.onDataRead(ctx, streamId, data, padding, endOfStream); return bytesToReturn; - } catch (Http2Exception e) { - // If an exception happened during delivery, the listener may have returned part - // of the bytes before the error occurred. If that's the case, subtract that from - // the total processed bytes so that we don't return too many bytes. - int delta = unconsumedBytes - unconsumedBytes(stream); - bytesToReturn -= delta; - throw e; - } catch (RuntimeException e) { + } catch (Http2Exception | RuntimeException e) { // If an exception happened during delivery, the listener may have returned part // of the bytes before the error occurred. If that's the case, subtract that from // the total processed bytes so that we don't return too many bytes. diff --git a/common/src/main/java/io/netty/util/internal/CleanerJava9.java b/common/src/main/java/io/netty/util/internal/CleanerJava9.java index 3a0c5854c3..12421b1576 100644 --- a/common/src/main/java/io/netty/util/internal/CleanerJava9.java +++ b/common/src/main/java/io/netty/util/internal/CleanerJava9.java @@ -46,11 +46,7 @@ final class CleanerJava9 implements Cleaner { "invokeCleaner", ByteBuffer.class); m.invoke(PlatformDependent0.UNSAFE, buffer); return m; - } catch (NoSuchMethodException e) { - return e; - } catch (InvocationTargetException e) { - return e; - } catch (IllegalAccessException e) { + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { return e; } } @@ -100,9 +96,7 @@ final class CleanerJava9 implements Cleaner { public Exception run() { try { INVOKE_CLEANER.invoke(PlatformDependent0.UNSAFE, buffer); - } catch (InvocationTargetException e) { - return e; - } catch (IllegalAccessException e) { + } catch (InvocationTargetException | IllegalAccessException e) { return e; } return null; diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java index df45d1614a..059f5376cb 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java @@ -93,17 +93,11 @@ final class PlatformDependent0 { } // the unsafe instance return unsafeField.get(null); - } catch (NoSuchFieldException e) { + } catch (NoSuchFieldException | SecurityException + | IllegalAccessException | NoClassDefFoundError e) { return e; - } catch (SecurityException e) { - return e; - } catch (IllegalAccessException e) { - return e; - } catch (NoClassDefFoundError e) { - // Also catch NoClassDefFoundError in case someone uses for example OSGI and it made - // Unsafe unloadable. - return e; - } + } // Also catch NoClassDefFoundError in case someone uses for example OSGI and it made + // Unsafe unloadable. } }); @@ -132,9 +126,7 @@ final class PlatformDependent0 { finalUnsafe.getClass().getDeclaredMethod( "copyMemory", Object.class, long.class, Object.class, long.class, long.class); return null; - } catch (NoSuchMethodException e) { - return e; - } catch (SecurityException e) { + } catch (NoSuchMethodException | SecurityException e) { return e; } } @@ -169,9 +161,7 @@ final class PlatformDependent0 { return null; } return field; - } catch (NoSuchFieldException e) { - return e; - } catch (SecurityException e) { + } catch (NoSuchFieldException | SecurityException e) { return e; } } @@ -226,9 +216,7 @@ final class PlatformDependent0 { return cause; } return constructor; - } catch (NoSuchMethodException e) { - return e; - } catch (SecurityException e) { + } catch (NoSuchMethodException | SecurityException e) { return e; } } @@ -241,11 +229,7 @@ final class PlatformDependent0 { ((Constructor) maybeDirectBufferConstructor).newInstance(address, 1); directBufferConstructor = (Constructor) maybeDirectBufferConstructor; logger.debug("direct buffer constructor: available"); - } catch (InstantiationException e) { - directBufferConstructor = null; - } catch (IllegalAccessException e) { - directBufferConstructor = null; - } catch (InvocationTargetException e) { + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { directBufferConstructor = null; } } else { @@ -294,15 +278,8 @@ final class PlatformDependent0 { return cause; } return unalignedMethod.invoke(null); - } catch (NoSuchMethodException e) { - return e; - } catch (SecurityException e) { - return e; - } catch (IllegalAccessException e) { - return e; - } catch (ClassNotFoundException e) { - return e; - } catch (InvocationTargetException e) { + } catch (NoSuchMethodException | SecurityException + | IllegalAccessException | ClassNotFoundException | InvocationTargetException e) { return e; } } @@ -346,9 +323,7 @@ final class PlatformDependent0 { try { return finalInternalUnsafe.getClass().getDeclaredMethod( "allocateUninitializedArray", Class.class, int.class); - } catch (NoSuchMethodException e) { - return e; - } catch (SecurityException e) { + } catch (NoSuchMethodException | SecurityException e) { return e; } } @@ -360,9 +335,7 @@ final class PlatformDependent0 { byte[] bytes = (byte[]) m.invoke(finalInternalUnsafe, byte.class, 8); assert bytes.length == 8; allocateArrayMethod = m; - } catch (IllegalAccessException e) { - maybeException = e; - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException e) { maybeException = e; } } @@ -459,9 +432,7 @@ final class PlatformDependent0 { static byte[] allocateUninitializedArray(int size) { try { return (byte[]) ALLOCATE_ARRAY_METHOD.invoke(INTERNAL_UNSAFE, byte.class, size); - } catch (IllegalAccessException e) { - throw new Error(e); - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException e) { throw new Error(e); } } diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslX509TrustManagerWrapper.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslX509TrustManagerWrapper.java index 0a0db0bbf4..6261c1801d 100644 --- a/handler/src/main/java/io/netty/handler/ssl/OpenSslX509TrustManagerWrapper.java +++ b/handler/src/main/java/io/netty/handler/ssl/OpenSslX509TrustManagerWrapper.java @@ -119,9 +119,7 @@ final class OpenSslX509TrustManagerWrapper { } while (clazz != null); } throw new NoSuchFieldException(); - } catch (NoSuchFieldException e) { - return e; - } catch (SecurityException e) { + } catch (NoSuchFieldException | SecurityException e) { return e; } } @@ -174,11 +172,7 @@ final class OpenSslX509TrustManagerWrapper { return (X509TrustManager) tm; } } - } catch (NoSuchAlgorithmException e) { - // This should never happen as we did the same in the static - // before. - PlatformDependent.throwException(e); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | KeyManagementException e) { // This should never happen as we did the same in the static // before. PlatformDependent.throwException(e); diff --git a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java index 837b37320b..edf3d4573c 100644 --- a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java +++ b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java @@ -276,9 +276,7 @@ public final class NioEventLoop extends SingleThreadEventLoop { selectedKeysField.set(unwrappedSelector, selectedKeySet); publicSelectedKeysField.set(unwrappedSelector, selectedKeySet); return null; - } catch (NoSuchFieldException e) { - return e; - } catch (IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { return e; } } @@ -311,8 +309,8 @@ public final class NioEventLoop extends SingleThreadEventLoop { @Override protected Queue newTaskQueue(int maxPendingTasks) { // This event loop never calls takeTask() - return maxPendingTasks == Integer.MAX_VALUE ? PlatformDependent.newMpscQueue() - : PlatformDependent.newMpscQueue(maxPendingTasks); + return maxPendingTasks == Integer.MAX_VALUE ? PlatformDependent.newMpscQueue() + : PlatformDependent.newMpscQueue(maxPendingTasks); } /**