From 278c36af0ca9f0e97d6d321a88c413155483c509 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 20 Jun 2016 11:40:12 +0200 Subject: [PATCH] Merge ThrowableUtils into ThrowableUtil. Motivation: We should merge ThrowableUtils into ThrowableUtil as this name is more consistent with the naming of utility classes in netty. Modifications: Merge classes. Result: More consistent naming --- .../io/netty/util/internal/ThrowableUtil.java | 26 ++++++++++ .../netty/util/internal/ThrowableUtils.java | 48 ------------------- .../AbstractChannelHandlerContext.java | 4 +- .../netty/channel/ChannelOutboundBuffer.java | 6 +-- .../channel/CombinedChannelDuplexHandler.java | 4 +- 5 files changed, 33 insertions(+), 55 deletions(-) delete mode 100644 common/src/main/java/io/netty/util/internal/ThrowableUtils.java 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 2e504bfa52..97d04f7cc1 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java @@ -23,7 +23,7 @@ import io.netty.util.Recycler; import io.netty.util.ReferenceCountUtil; import io.netty.util.ResourceLeakHint; 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; @@ -281,7 +281,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap "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 882f4fea05..4266036581 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 ba78f853b8..c1f156080a 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