diff options
author | Ulf Adams <ulfjack@google.com> | 2016-08-11 12:39:46 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2016-08-12 08:49:35 +0000 |
commit | 653a16a49b83bd96b18ee71c8123f53305811472 (patch) | |
tree | 64a878f636aff27a4448caa5827a4b0852336093 /src/main/java/com/google/devtools/build/lib | |
parent | 67ad82a319ff8959e69e774e7c15d3af904ec23d (diff) |
Replace calls to <class>.newInstance with <class>.getConstructor().newInstance.
This is safer; newInstance on class objects bypasses exception checking.
--
MOS_MIGRATED_REVID=129976805
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index dc4920d1dc..5a4ebd0875 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -527,7 +527,7 @@ public final class BlazeRuntime { ImmutableList.Builder<BlazeModule> result = ImmutableList.builder(); for (Class<? extends BlazeModule> moduleClass : moduleClasses) { try { - BlazeModule module = moduleClass.newInstance(); + BlazeModule module = moduleClass.getConstructor().newInstance(); result.add(module); } catch (Throwable e) { throw new IllegalStateException("Cannot instantiate module " + moduleClass.getName(), e); @@ -782,11 +782,11 @@ public final class BlazeRuntime { // gRPC server is not compiled in so that we don't need gRPC for bootstrapping. Class<?> factoryClass = Class.forName( "com.google.devtools.build.lib.server.GrpcServerImpl$Factory"); - RPCServer.Factory factory = (RPCServer.Factory) factoryClass.newInstance(); + RPCServer.Factory factory = (RPCServer.Factory) factoryClass.getConstructor().newInstance(); return factory.create(commandExecutor, runtime.getClock(), startupOptions.commandPort, runtime.getServerDirectory(), startupOptions.maxIdleSeconds); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (ReflectiveOperationException | IllegalArgumentException e) { throw new AbruptExitException("gRPC server not compiled in", ExitCode.BLAZE_INTERNAL_ERROR); } } |