Replace calls to <class>.newInstance with <class>.getConstructor().newInstance. This is safer; newInstance on class objects bypasses exception checking. -- MOS_MIGRATED_REVID=129976805
diff --git a/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java b/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java index 02357ff..41091af 100644 --- a/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java +++ b/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java
@@ -23,7 +23,6 @@ import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.TriState; import com.google.devtools.build.lib.syntax.Type; - import java.util.HashMap; import java.util.LinkedList; import java.util.Map; @@ -258,8 +257,8 @@ ConfiguredRuleClassProvider ruleClassProvider) { if (ruleClassProvider == null) { try { - return usingClass.newInstance(); - } catch (IllegalAccessException | InstantiationException e) { + return usingClass.getConstructor().newInstance(); + } catch (ReflectiveOperationException | IllegalArgumentException e) { throw new IllegalStateException(e); } }
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 dc4920d..5a4ebd0 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 @@ 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 @@ // 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); } }