From 54db9ec725d2b2f74436b15e6c7aef196f098a81 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 4 Nov 2013 19:42:33 +0900 Subject: [PATCH] Use StringUtil.simpleClassName(..) instead of Class.getSimpleName() where necessary - Class.getSimpleName() doesn't render anonymous classes very well - + some minor cleanup --- .../src/main/java/io/netty/buffer/AbstractByteBuf.java | 5 +++-- .../main/java/io/netty/buffer/DefaultByteBufHolder.java | 3 ++- buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java | 3 ++- .../main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java | 3 ++- .../io/netty/handler/codec/http/DefaultHttpContent.java | 3 ++- .../io/netty/handler/codec/http/DefaultHttpMessage.java | 2 +- .../io/netty/handler/codec/http/DefaultHttpRequest.java | 2 +- .../io/netty/handler/codec/http/DefaultHttpResponse.java | 2 +- .../io/netty/handler/codec/http/HttpObjectEncoder.java | 9 +++++---- .../handler/codec/http/websocketx/WebSocketFrame.java | 3 ++- .../netty/handler/codec/spdy/DefaultSpdyDataFrame.java | 2 +- .../netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java | 2 +- .../handler/codec/spdy/DefaultSpdyHeadersFrame.java | 2 +- .../netty/handler/codec/spdy/DefaultSpdyPingFrame.java | 2 +- .../handler/codec/spdy/DefaultSpdyRstStreamFrame.java | 2 +- .../handler/codec/spdy/DefaultSpdySettingsFrame.java | 2 +- .../handler/codec/spdy/DefaultSpdySynReplyFrame.java | 2 +- .../handler/codec/spdy/DefaultSpdySynStreamFrame.java | 2 +- .../handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java | 2 +- .../io/netty/handler/codec/ReplayingDecoderBuffer.java | 3 ++- common/src/main/java/io/netty/util/HashedWheelTimer.java | 3 ++- .../main/java/io/netty/util/ResourceLeakDetector.java | 5 +++-- .../util/internal/logging/AbstractInternalLogger.java | 4 +++- .../http/websocketx/autobahn/AutobahnServerHandler.java | 3 ++- .../netty/testsuite/transport/sctp/AbstractSctpTest.java | 5 +++-- .../transport/socket/AbstractClientSocketTest.java | 3 ++- .../testsuite/transport/socket/AbstractDatagramTest.java | 3 ++- .../transport/socket/AbstractServerSocketTest.java | 3 ++- .../testsuite/transport/socket/AbstractSocketTest.java | 3 ++- .../main/java/io/netty/bootstrap/AbstractBootstrap.java | 7 ++++--- .../main/java/io/netty/bootstrap/ServerBootstrap.java | 3 ++- .../java/io/netty/channel/DefaultChannelPipeline.java | 2 +- .../java/io/netty/channel/group/DefaultChannelGroup.java | 4 ++-- .../io/netty/channel/local/LocalChannelRegistry.java | 4 ++-- 34 files changed, 64 insertions(+), 44 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java index e466407f07..1ec4afa71f 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java @@ -18,6 +18,7 @@ package io.netty.buffer; import io.netty.util.IllegalReferenceCountException; import io.netty.util.ResourceLeakDetector; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.StringUtil; import java.io.IOException; import java.io.InputStream; @@ -1086,11 +1087,11 @@ public abstract class AbstractByteBuf extends ByteBuf { @Override public String toString() { if (refCnt() == 0) { - return getClass().getSimpleName() + "(freed)"; + return StringUtil.simpleClassName(this) + "(freed)"; } StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(ridx: "); buf.append(readerIndex); buf.append(", widx: "); diff --git a/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java b/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java index 9b615f2bb0..974138a9ae 100644 --- a/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java +++ b/buffer/src/main/java/io/netty/buffer/DefaultByteBufHolder.java @@ -16,6 +16,7 @@ package io.netty.buffer; import io.netty.util.IllegalReferenceCountException; +import io.netty.util.internal.StringUtil; /** * Default implementation of a {@link ByteBufHolder} that holds it's data in a {@link ByteBuf}. @@ -79,6 +80,6 @@ public class DefaultByteBufHolder implements ByteBufHolder { @Override public String toString() { - return getClass().getSimpleName() + '(' + content().toString() + ')'; + return StringUtil.simpleClassName(this) + '(' + content().toString() + ')'; } } diff --git a/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java b/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java index f83b265fa2..4364a52561 100644 --- a/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java @@ -18,6 +18,7 @@ package io.netty.buffer; import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.StringUtil; import java.io.InputStream; import java.io.OutputStream; @@ -64,7 +65,7 @@ public final class EmptyByteBuf extends ByteBuf { this.alloc = alloc; this.order = order; - str = getClass().getSimpleName() + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE"); + str = StringUtil.simpleClassName(this) + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE"); } @Override diff --git a/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java b/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java index 4b2f4f7772..47efe9f1ce 100644 --- a/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java +++ b/buffer/src/main/java/io/netty/buffer/ReadOnlyByteBufferBuf.java @@ -16,6 +16,7 @@ package io.netty.buffer; import io.netty.util.ResourceLeak; +import io.netty.util.internal.StringUtil; import java.io.IOException; import java.io.InputStream; @@ -40,7 +41,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf { public ReadOnlyByteBufferBuf(ByteBufAllocator allocator, ByteBuffer buffer) { super(buffer.remaining()); if (!buffer.isReadOnly()) { - throw new IllegalArgumentException("must be a readonly buffer: " + buffer.getClass().getSimpleName()); + throw new IllegalArgumentException("must be a readonly buffer: " + StringUtil.simpleClassName(buffer)); } this.allocator = allocator; diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java index df63af4c70..185a4de9aa 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpContent.java @@ -16,6 +16,7 @@ package io.netty.handler.codec.http; import io.netty.buffer.ByteBuf; +import io.netty.util.internal.StringUtil; /** * The default {@link HttpContent} implementation. @@ -78,6 +79,6 @@ public class DefaultHttpContent extends DefaultHttpObject implements HttpContent @Override public String toString() { - return getClass().getSimpleName() + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')'; + return StringUtil.simpleClassName(this) + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')'; } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java index b3b6ff71bd..8f66cb345d 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java @@ -50,7 +50,7 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(version: "); buf.append(getProtocolVersion().text()); buf.append(", keepAlive: "); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpRequest.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpRequest.java index afab54b98a..e2f3463955 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpRequest.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpRequest.java @@ -81,7 +81,7 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append(", decodeResult: "); buf.append(getDecoderResult()); buf.append(')'); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpResponse.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpResponse.java index fae07f8d05..3eb95cf7e1 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpResponse.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpResponse.java @@ -61,7 +61,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(decodeResult: "); buf.append(getDecoderResult()); buf.append(')'); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java index 4425b35a2d..35312ab5f4 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java @@ -20,6 +20,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.FileRegion; import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.util.CharsetUtil; +import io.netty.util.internal.StringUtil; import java.util.List; import java.util.Map; @@ -60,7 +61,7 @@ public abstract class HttpObjectEncoder extends MessageTo protected void encode(ChannelHandlerContext ctx, Object msg, List out) throws Exception { if (msg instanceof HttpMessage) { if (state != ST_INIT) { - throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); + throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg)); } @SuppressWarnings({ "unchecked", "CastConflictsWithInstanceof" }) @@ -76,7 +77,7 @@ public abstract class HttpObjectEncoder extends MessageTo } if (msg instanceof HttpContent || msg instanceof ByteBuf || msg instanceof FileRegion) { if (state == ST_INIT) { - throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); + throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg)); } int contentLength = contentLength(msg); @@ -148,7 +149,7 @@ public abstract class HttpObjectEncoder extends MessageTo if (msg instanceof FileRegion) { return ((FileRegion) msg).retain(); } - throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); + throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg)); } private static int contentLength(Object msg) { @@ -161,7 +162,7 @@ public abstract class HttpObjectEncoder extends MessageTo if (msg instanceof FileRegion) { return (int) ((FileRegion) msg).count(); } - throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); + throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg)); } private static void encodeHeaders(ByteBuf buf, HttpHeaders headers) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrame.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrame.java index f132407c44..054bda4cda 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrame.java @@ -17,6 +17,7 @@ package io.netty.handler.codec.http.websocketx; import io.netty.buffer.ByteBuf; import io.netty.buffer.DefaultByteBufHolder; +import io.netty.util.internal.StringUtil; /** * Base class for web socket frames @@ -67,7 +68,7 @@ public abstract class WebSocketFrame extends DefaultByteBufHolder { @Override public String toString() { - return getClass().getSimpleName() + "(data: " + content().toString() + ')'; + return StringUtil.simpleClassName(this) + "(data: " + content().toString() + ')'; } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java index 4a5b32a262..cfdb1d07cb 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java @@ -122,7 +122,7 @@ public class DefaultSpdyDataFrame extends DefaultSpdyStreamFrame implements Spdy @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(last: "); buf.append(isLast()); buf.append(')'); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java index 956fa7de70..c4515f51ac 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java @@ -84,7 +84,7 @@ public class DefaultSpdyGoAwayFrame implements SpdyGoAwayFrame { @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append(StringUtil.NEWLINE); buf.append("--> Last-good-stream-ID = "); buf.append(getLastGoodStreamId()); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java index b315590903..e614c18075 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java @@ -80,7 +80,7 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(last: "); buf.append(isLast()); buf.append(')'); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java index 17d7b14363..667fa0eccc 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java @@ -47,7 +47,7 @@ public class DefaultSpdyPingFrame implements SpdyPingFrame { @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append(StringUtil.NEWLINE); buf.append("--> ID = "); buf.append(getId()); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java index bd259ae1c2..ee58491743 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java @@ -72,7 +72,7 @@ public class DefaultSpdyRstStreamFrame extends DefaultSpdyStreamFrame @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append(StringUtil.NEWLINE); buf.append("--> Stream-ID = "); buf.append(getStreamId()); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java index 79f63054b2..83c76a5641 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java @@ -153,7 +153,7 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame { @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append(StringUtil.NEWLINE); appendSettings(buf); buf.setLength(buf.length() - StringUtil.NEWLINE.length()); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java index ef5b61033c..331c3e818e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java @@ -53,7 +53,7 @@ public class DefaultSpdySynReplyFrame extends DefaultSpdyHeadersFrame @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(last: "); buf.append(isLast()); buf.append(')'); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java index c2bba9deb1..ea97dc11e3 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java @@ -104,7 +104,7 @@ public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append("(last: "); buf.append(isLast()); buf.append("; unidirectional: "); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java index b1905ba75d..08833a5f63 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java @@ -70,7 +70,7 @@ public class DefaultSpdyWindowUpdateFrame implements SpdyWindowUpdateFrame { @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append(StringUtil.NEWLINE); buf.append("--> Stream-ID = "); buf.append(getStreamId()); diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java index fb12a0d9ed..b3d4d686d1 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java @@ -21,6 +21,7 @@ import io.netty.buffer.ByteBufProcessor; import io.netty.buffer.SwappedByteBuf; import io.netty.buffer.Unpooled; import io.netty.util.Signal; +import io.netty.util.internal.StringUtil; import java.io.InputStream; import java.io.OutputStream; @@ -788,7 +789,7 @@ final class ReplayingDecoderBuffer extends ByteBuf { @Override public String toString() { - return getClass().getSimpleName() + '(' + + return StringUtil.simpleClassName(this) + '(' + "ridx=" + readerIndex() + ", " + diff --git a/common/src/main/java/io/netty/util/HashedWheelTimer.java b/common/src/main/java/io/netty/util/HashedWheelTimer.java index 0a2f26f91c..6c5d575f4f 100644 --- a/common/src/main/java/io/netty/util/HashedWheelTimer.java +++ b/common/src/main/java/io/netty/util/HashedWheelTimer.java @@ -16,6 +16,7 @@ package io.netty.util; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -541,7 +542,7 @@ public class HashedWheelTimer implements Timer { long remaining = deadline - currentTime + startTime; StringBuilder buf = new StringBuilder(192); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append('('); buf.append("deadline: "); diff --git a/common/src/main/java/io/netty/util/ResourceLeakDetector.java b/common/src/main/java/io/netty/util/ResourceLeakDetector.java index f60731e28c..653d393406 100644 --- a/common/src/main/java/io/netty/util/ResourceLeakDetector.java +++ b/common/src/main/java/io/netty/util/ResourceLeakDetector.java @@ -17,6 +17,7 @@ package io.netty.util; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -70,7 +71,7 @@ public final class ResourceLeakDetector { private long leakCheckCnt; public ResourceLeakDetector(Class resourceType) { - this(resourceType.getSimpleName()); + this(StringUtil.simpleClassName(resourceType)); } public ResourceLeakDetector(String resourceType) { @@ -78,7 +79,7 @@ public final class ResourceLeakDetector { } public ResourceLeakDetector(Class resourceType, int samplingInterval, long maxActive) { - this(resourceType.getSimpleName(), samplingInterval, maxActive); + this(StringUtil.simpleClassName(resourceType), samplingInterval, maxActive); } public ResourceLeakDetector(String resourceType, int samplingInterval, long maxActive) { diff --git a/common/src/main/java/io/netty/util/internal/logging/AbstractInternalLogger.java b/common/src/main/java/io/netty/util/internal/logging/AbstractInternalLogger.java index 984f70fd65..afb45b21d4 100644 --- a/common/src/main/java/io/netty/util/internal/logging/AbstractInternalLogger.java +++ b/common/src/main/java/io/netty/util/internal/logging/AbstractInternalLogger.java @@ -15,6 +15,8 @@ */ package io.netty.util.internal.logging; +import io.netty.util.internal.StringUtil; + import java.io.ObjectStreamException; import java.io.Serializable; @@ -183,6 +185,6 @@ public abstract class AbstractInternalLogger implements InternalLogger, Serializ @Override public String toString() { - return getClass().getSimpleName() + '(' + name() + ')'; + return StringUtil.simpleClassName(this) + '(' + name() + ')'; } } diff --git a/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServerHandler.java b/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServerHandler.java index 9327aeddb6..44f8c03f2b 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServerHandler.java +++ b/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServerHandler.java @@ -35,6 +35,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; import io.netty.util.CharsetUtil; +import io.netty.util.internal.StringUtil; import java.util.logging.Level; import java.util.logging.Logger; @@ -97,7 +98,7 @@ public class AutobahnServerHandler extends ChannelInboundHandlerAdapter { private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) { if (logger.isLoggable(Level.FINE)) { logger.fine(String.format( - "Channel %s received %s", ctx.channel().hashCode(), frame.getClass().getSimpleName())); + "Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame))); } if (frame instanceof CloseWebSocketFrame) { diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/sctp/AbstractSctpTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/sctp/AbstractSctpTest.java index 4151985a24..ff977ee53e 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/sctp/AbstractSctpTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/sctp/AbstractSctpTest.java @@ -22,6 +22,7 @@ import io.netty.channel.ChannelOption; import io.netty.testsuite.transport.sctp.SctpTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import org.junit.Rule; @@ -37,7 +38,7 @@ public abstract class AbstractSctpTest { private static final List, Factory>> COMBO = SctpTestPermutation.sctpChannel(); - private static List ALLOCATORS = SctpTestPermutation.allocator(); + private static final List ALLOCATORS = SctpTestPermutation.allocator(); @Rule public final TestName testName = new TestName(); @@ -65,7 +66,7 @@ public abstract class AbstractSctpTest { cb.option(ChannelOption.ALLOCATOR, allocator); logger.info(String.format( "Running: %s %d of %d (%s + %s) with %s", - testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName())); + testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator))); try { Method m = getClass().getDeclaredMethod( testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java index 595ed7e186..9ffd7d0d12 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java @@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import org.junit.Rule; @@ -54,7 +55,7 @@ public abstract class AbstractClientSocketTest { cb.option(ChannelOption.ALLOCATOR, allocator); logger.info(String.format( "Running: %s %d of %d with %s", - testName.getMethodName(), ++ i, COMBO.size(), allocator.getClass().getSimpleName())); + testName.getMethodName(), ++ i, COMBO.size(), StringUtil.simpleClassName(allocator))); try { Method m = getClass().getDeclaredMethod( testName.getMethodName(), Bootstrap.class); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java index eeb7e3ff56..db7389b37f 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java @@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import org.junit.Rule; @@ -60,7 +61,7 @@ public abstract class AbstractDatagramTest { cb.option(ChannelOption.ALLOCATOR, allocator); logger.info(String.format( "Running: %s %d of %d (%s + %s) with %s", - testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName())); + testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator))); try { Method m = getClass().getDeclaredMethod( testName.getMethodName(), Bootstrap.class, Bootstrap.class); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java index 2b45ed671b..59e922eae4 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java @@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import org.junit.Rule; @@ -57,7 +58,7 @@ public abstract class AbstractServerSocketTest { logger.info(String.format( "Running: %s %d of %d (%s) with %s", - testName.getMethodName(), ++ i, COMBO.size(), sb, allocator.getClass().getSimpleName())); + testName.getMethodName(), ++ i, COMBO.size(), sb, StringUtil.simpleClassName(allocator))); try { Method m = getClass().getDeclaredMethod( testName.getMethodName(), ServerBootstrap.class); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java index 660613b089..c190d1e819 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java @@ -22,6 +22,7 @@ import io.netty.channel.ChannelOption; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import org.junit.Rule; @@ -67,7 +68,7 @@ public abstract class AbstractSocketTest { logger.info(String.format( "Running: %s %d of %d (%s + %s) with %s", - testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName())); + testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator))); try { Method m = getClass().getDeclaredMethod( testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); diff --git a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java index d8bec45646..9a6c18781d 100644 --- a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java @@ -26,6 +26,7 @@ import io.netty.channel.ChannelPromise; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; import io.netty.util.AttributeKey; +import io.netty.util.internal.StringUtil; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -377,11 +378,11 @@ public abstract class AbstractBootstrap, C ext @Override public String toString() { StringBuilder buf = new StringBuilder(); - buf.append(getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(this)); buf.append('('); if (group != null) { buf.append("group: "); - buf.append(group.getClass().getSimpleName()); + buf.append(StringUtil.simpleClassName(group)); buf.append(", "); } if (channelFactory != null) { @@ -440,7 +441,7 @@ public abstract class AbstractBootstrap, C ext @Override public String toString() { - return clazz.getSimpleName() + ".class"; + return StringUtil.simpleClassName(clazz) + ".class"; } } } diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index d4ac7f54bc..bbdc2862e7 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -27,6 +27,7 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.socket.SocketChannel; import io.netty.util.AttributeKey; +import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -286,7 +287,7 @@ public final class ServerBootstrap extends AbstractBootstrap implements Channel @Override public String toString() { - return getClass().getSimpleName() + - "(name: " + name() + ", size: " + size() + ')'; + return StringUtil.simpleClassName(this) + "(name: " + name() + ", size: " + size() + ')'; } } diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java b/transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java index 8a5b18e477..3aca5369dd 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannelRegistry.java @@ -18,6 +18,7 @@ package io.netty.channel.local; import io.netty.channel.Channel; import io.netty.channel.ChannelException; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.StringUtil; import java.net.SocketAddress; import java.util.concurrent.ConcurrentMap; @@ -32,8 +33,7 @@ final class LocalChannelRegistry { throw new ChannelException("already bound"); } if (!(localAddress instanceof LocalAddress)) { - throw new ChannelException( - "unsupported address type: " + localAddress.getClass().getSimpleName()); + throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress)); } LocalAddress addr = (LocalAddress) localAddress;