Use Constructor for reflective class instantiation.

Motivation:
Calling `newInstance()` on a Class object can bypass compile time
checked Exception propagation.  This is noted in Java Puzzlers,
as well as in ErrorProne:
http://errorprone.info/bugpattern/ClassNewInstance

Modifications:
Use the niladic constructor to create a new instance.

Result:
Compile time safety for checked exceptions
This commit is contained in:
Carl Mastrangelo 2017-08-17 20:17:36 -07:00 committed by Norman Maurer
parent 703dc8c95d
commit ca8967bc0b
2 changed files with 2 additions and 2 deletions

View File

@ -78,7 +78,7 @@ public final class CaliperRunner {
public static Run execute(final String name,
final Class<? extends CaliperBench> klaz) throws Exception {
final CaliperBench booter = klaz.newInstance();
final CaliperBench booter = klaz.getConstructor().newInstance();
final List<Map<String, String>> varsSet = product(booter);

View File

@ -484,7 +484,7 @@ public abstract class AbstractBootstrap<B extends AbstractBootstrap<B, C>, C ext
@Override
public T newChannel() {
try {
return clazz.newInstance();
return clazz.getConstructor().newInstance();
} catch (Throwable t) {
throw new ChannelException("Unable to create Channel from class " + clazz, t);
}