From a79dfe74b75fb3c6f016e3c327d8df24e5fb4593 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 16 Dec 2013 13:54:23 +0900 Subject: [PATCH] Prevent NPE from StringUtil.simpleName(..) --- .../main/java/io/netty/util/internal/StringUtil.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/io/netty/util/internal/StringUtil.java b/common/src/main/java/io/netty/util/internal/StringUtil.java index 340489f44d..7aabe7fdfd 100644 --- a/common/src/main/java/io/netty/util/internal/StringUtil.java +++ b/common/src/main/java/io/netty/util/internal/StringUtil.java @@ -36,6 +36,7 @@ public final class StringUtil { try { newLine = new Formatter().format("%n").toString(); } catch (Exception e) { + // Should not reach here, but just in case. newLine = "\n"; } @@ -89,7 +90,11 @@ public final class StringUtil { * The shortcut to {@link #simpleClassName(Class) simpleClassName(o.getClass())}. */ public static String simpleClassName(Object o) { - return simpleClassName(o.getClass()); + if (o == null) { + return "null_object"; + } else { + return simpleClassName(o.getClass()); + } } /** @@ -97,6 +102,10 @@ public final class StringUtil { * with anonymous classes. */ public static String simpleClassName(Class clazz) { + if (clazz == null) { + return "null_class"; + } + Package pkg = clazz.getPackage(); if (pkg != null) { return clazz.getName().substring(pkg.getName().length() + 1);