From 8db0f3ac6e2c7c914356745e981e91fb72fa0f46 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 30 Jan 2022 18:21:28 +0100 Subject: [PATCH] Fix uninjection from empty pipeline Closes #2788 --- .../platform/LegacyViaInjector.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java b/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java index 21c787955..3f423fe29 100644 --- a/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java +++ b/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java @@ -28,6 +28,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; import org.checkerframework.checker.nullness.qual.Nullable; import java.lang.reflect.Field; @@ -110,11 +111,22 @@ public abstract class LegacyViaInjector implements ViaInjector { public void uninject() throws ReflectiveOperationException { //TODO uninject connections for (ChannelFuture future : injectedFutures) { - List names = future.channel().pipeline().names(); - ChannelHandler bootstrapAcceptor = null; + // Default to first + ChannelPipeline pipeline = future.channel().pipeline(); + ChannelHandler bootstrapAcceptor = pipeline.first(); + if (bootstrapAcceptor == null) { + Via.getPlatform().getLogger().info("Empty pipeline, nothing to uninject"); + continue; + } + // Pick best - for (String name : names) { - ChannelHandler handler = future.channel().pipeline().get(name); + for (String name : pipeline.names()) { + ChannelHandler handler = pipeline.get(name); + if (handler == null) { + Via.getPlatform().getLogger().warning("Could not get handler " + name); + continue; + } + try { if (ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class) instanceof WrappedChannelInitializer) { bootstrapAcceptor = handler; @@ -124,11 +136,6 @@ public abstract class LegacyViaInjector implements ViaInjector { } } - if (bootstrapAcceptor == null) { - // Default to first - bootstrapAcceptor = future.channel().pipeline().first(); - } - try { ChannelInitializer initializer = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); if (initializer instanceof WrappedChannelInitializer) {