Optimize code: Fix Constructor to determine illegal logic problems (#3197)
author于玉桔 <769213327@qq.com>
Sun, 20 Jan 2019 01:34:47 +0000 (09:34 +0800)
committerHuxing Zhang <huxing.zhang@gmail.com>
Sun, 20 Jan 2019 01:34:47 +0000 (09:34 +0800)
dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java

index 2198709..18998dc 100644 (file)
@@ -520,7 +520,14 @@ public class PojoUtils {
         } catch (Throwable t) {\r
             try {\r
                 Constructor<?>[] constructors = cls.getDeclaredConstructors();\r
-                if (constructors != null && constructors.length == 0) {\r
+                /**\r
+                 * From Javadoc java.lang.Class#getDeclaredConstructors\r
+                 * This method returns an array of Constructor objects reflecting all the constructors\r
+                 * declared by the class represented by this Class object.\r
+                 * This method returns an array of length 0,\r
+                 * if this Class object represents an interface, a primitive type, an array class, or void.\r
+                 */\r
+                if (constructors.length == 0) {\r
                     throw new RuntimeException("Illegal constructor: " + cls.getName());\r
                 }\r
                 Constructor<?> constructor = constructors[0];\r