Merge pull request #21913 from dreis2211

* gh-21913:
  Use Class.getDeclaredConstructor().newInstance()

Closes gh-21913
pull/22256/head
Andy Wilkinson 4 years ago
commit c3c1f2d29f

@ -204,7 +204,7 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration {
private Object getNoJtaPlatformManager() { private Object getNoJtaPlatformManager() {
for (String candidate : NO_JTA_PLATFORM_CLASSES) { for (String candidate : NO_JTA_PLATFORM_CLASSES) {
try { try {
return Class.forName(candidate).newInstance(); return Class.forName(candidate).getDeclaredConstructor().newInstance();
} }
catch (Exception ex) { catch (Exception ex) {
// Continue searching // Continue searching

@ -538,7 +538,8 @@ class ServerPropertiesTests {
} }
private AbstractProtocol<?> getDefaultProtocol() throws Exception { private AbstractProtocol<?> getDefaultProtocol() throws Exception {
return (AbstractProtocol<?>) Class.forName(TomcatServletWebServerFactory.DEFAULT_PROTOCOL).newInstance(); return (AbstractProtocol<?>) Class.forName(TomcatServletWebServerFactory.DEFAULT_PROTOCOL)
.getDeclaredConstructor().newInstance();
} }
private void bind(String name, String value) { private void bind(String name, String value) {

@ -132,7 +132,7 @@ public class Handler extends URLStreamHandler {
for (String handlerClassName : FALLBACK_HANDLERS) { for (String handlerClassName : FALLBACK_HANDLERS) {
try { try {
Class<?> handlerClass = Class.forName(handlerClassName); Class<?> handlerClass = Class.forName(handlerClassName);
this.fallbackHandler = (URLStreamHandler) handlerClass.newInstance(); this.fallbackHandler = (URLStreamHandler) handlerClass.getDeclaredConstructor().newInstance();
return this.fallbackHandler; return this.fallbackHandler;
} }
catch (Exception ex) { catch (Exception ex) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ public class SummaryGeneratingListener extends ReflectiveWrapper {
public SummaryGeneratingListener(ClassLoader classLoader) throws Throwable { public SummaryGeneratingListener(ClassLoader classLoader) throws Throwable {
super(classLoader, "org.junit.platform.launcher.listeners.SummaryGeneratingListener"); super(classLoader, "org.junit.platform.launcher.listeners.SummaryGeneratingListener");
this.instance = this.type.newInstance(); this.instance = this.type.getDeclaredConstructor().newInstance();
} }
public TestExecutionSummary getSummary() throws Throwable { public TestExecutionSummary getSummary() throws Throwable {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -87,7 +87,7 @@ final class EnvironmentConverter {
private StandardEnvironment createEnvironment(Class<? extends StandardEnvironment> type) { private StandardEnvironment createEnvironment(Class<? extends StandardEnvironment> type) {
try { try {
return type.newInstance(); return type.getDeclaredConstructor().newInstance();
} }
catch (Exception ex) { catch (Exception ex) {
return new StandardEnvironment(); return new StandardEnvironment();

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,7 +55,7 @@ class JasperInitializer extends AbstractLifeCycle {
for (String className : INITIALIZER_CLASSES) { for (String className : INITIALIZER_CLASSES) {
try { try {
Class<?> initializerClass = ClassUtils.forName(className, null); Class<?> initializerClass = ClassUtils.forName(className, null);
return (ServletContainerInitializer) initializerClass.newInstance(); return (ServletContainerInitializer) initializerClass.getDeclaredConstructor().newInstance();
} }
catch (Exception ex) { catch (Exception ex) {
// Ignore // Ignore

@ -288,7 +288,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
private void addJasperInitializer(TomcatEmbeddedContext context) { private void addJasperInitializer(TomcatEmbeddedContext context) {
try { try {
ServletContainerInitializer initializer = (ServletContainerInitializer) ClassUtils ServletContainerInitializer initializer = (ServletContainerInitializer) ClassUtils
.forName("org.apache.jasper.servlet.JasperInitializer", null).newInstance(); .forName("org.apache.jasper.servlet.JasperInitializer", null).getDeclaredConstructor()
.newInstance();
context.addServletContainerInitializer(initializer, null); context.addServletContainerInitializer(initializer, null);
} }
catch (Exception ex) { catch (Exception ex) {

Loading…
Cancel
Save