From cb599135f99d20372d1c227814326df8995b37fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E7=8E=89=E6=A1=94?= <769213327@qq.com> Date: Sun, 20 Jan 2019 09:34:47 +0800 Subject: [PATCH] Optimize code: Fix Constructor to determine illegal logic problems (#3197) --- .../java/org/apache/dubbo/common/utils/PojoUtils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java index 2198709fb73..18998dc6239 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java @@ -520,7 +520,14 @@ private static Object newInstance(Class cls) { } catch (Throwable t) { try { Constructor[] constructors = cls.getDeclaredConstructors(); - if (constructors != null && constructors.length == 0) { + /** + * From Javadoc java.lang.Class#getDeclaredConstructors + * This method returns an array of Constructor objects reflecting all the constructors + * declared by the class represented by this Class object. + * This method returns an array of length 0, + * if this Class object represents an interface, a primitive type, an array class, or void. + */ + if (constructors.length == 0) { throw new RuntimeException("Illegal constructor: " + cls.getName()); } Constructor constructor = constructors[0];