Skip to content

Commit

Permalink
Optimize code: Fix Constructor to determine illegal logic problems (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyuguang authored and ralf0131 committed Jan 20, 2019
1 parent 576a413 commit cb59913
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit cb59913

Please sign in to comment.