diff --git a/common/src/main/java/io/netty/util/internal/ThrowableUtil.java b/common/src/main/java/io/netty/util/internal/ThrowableUtil.java index 790196b9c2..dcb532ec46 100644 --- a/common/src/main/java/io/netty/util/internal/ThrowableUtil.java +++ b/common/src/main/java/io/netty/util/internal/ThrowableUtil.java @@ -15,6 +15,10 @@ */ package io.netty.util.internal; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + public final class ThrowableUtil { private ThrowableUtil() { } @@ -26,4 +30,26 @@ public final class ThrowableUtil { cause.setStackTrace(new StackTraceElement[] { new StackTraceElement(clazz.getName(), method, null, -1)}); return cause; } + + /** + * Gets the stack trace from a Throwable as a String. + * + * @param cause the {@link Throwable} to be examined + * @return the stack trace as generated by {@link Throwable#printStackTrace(java.io.PrintWriter)} method. + */ + public static String stackTraceToString(Throwable cause) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream pout = new PrintStream(out); + cause.printStackTrace(pout); + pout.flush(); + try { + return new String(out.toByteArray()); + } finally { + try { + out.close(); + } catch (IOException ignore) { + // ignore as should never happen + } + } + } } diff --git a/common/src/main/java/io/netty/util/internal/ThrowableUtils.java b/common/src/main/java/io/netty/util/internal/ThrowableUtils.java deleted file mode 100644 index a592862584..0000000000 --- a/common/src/main/java/io/netty/util/internal/ThrowableUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2016 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.util.internal; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; - -public final class ThrowableUtils { - - /** - *

Gets the stack trace from a Throwable as a String.

- * - * @param throwable the Throwable to be examined - * @return the stack trace as generated by the exception's - * printStackTrace(PrintWriter) method - */ - public static String stackTraceToString(Throwable cause) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - PrintStream pout = new PrintStream(out); - cause.printStackTrace(pout); - pout.flush(); - try { - return new String(out.toByteArray()); - } finally { - try { - out.close(); - } catch (IOException ignore) { - // ignore as should never happen - } - } - } - - private ThrowableUtils() { } -} diff --git a/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java index 90f768800f..3db0bf4b07 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java @@ -20,7 +20,7 @@ import io.netty.util.DefaultAttributeMap; import io.netty.util.Recycler; import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.EventExecutor; -import io.netty.util.internal.ThrowableUtils; +import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.StringUtil; import io.netty.util.internal.SystemPropertyUtil; @@ -276,7 +276,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme "An exception {}" + "was thrown by a user handler's exceptionCaught() " + "method while handling the following exception:", - ThrowableUtils.stackTraceToString(error), cause); + ThrowableUtil.stackTraceToString(error), cause); } else if (logger.isWarnEnabled()) { logger.warn( "An exception '{}' [enable DEBUG level for full stacktrace] " + diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java index d2da7800df..b3e2e7a708 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java @@ -25,7 +25,7 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.FastThreadLocal; import io.netty.util.internal.InternalThreadLocalMap; import io.netty.util.internal.PlatformDependent; -import io.netty.util.internal.ThrowableUtils; +import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -677,7 +677,7 @@ public final class ChannelOutboundBuffer { } else { logger.warn( "Failed to mark a promise as success because it has failed already: {}, unnotified cause {}", - promise, ThrowableUtils.stackTraceToString(err)); + promise, ThrowableUtil.stackTraceToString(err)); } } } @@ -690,7 +690,7 @@ public final class ChannelOutboundBuffer { } else { logger.warn( "Failed to mark a promise as failure because it has failed already: {}, unnotified cause {}", - promise, ThrowableUtils.stackTraceToString(err), cause); + promise, ThrowableUtil.stackTraceToString(err), cause); } } } diff --git a/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java b/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java index cc10a3cd18..675d8a86d5 100644 --- a/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java +++ b/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java @@ -19,7 +19,7 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.util.Attribute; import io.netty.util.AttributeKey; import io.netty.util.concurrent.EventExecutor; -import io.netty.util.internal.ThrowableUtils; +import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -148,7 +148,7 @@ public class CombinedChannelDuplexHandler