Consistently use constructor-based instantiation instead of Class.newInstance / BeanUtils.instantiate
Issue: SPR-14486
This commit is contained in:
@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Simple implementation of a JNDI naming context builder.
|
||||
@@ -210,10 +211,10 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
|
||||
"Specified class does not implement [" + InitialContextFactory.class.getName() + "]: " + icf);
|
||||
}
|
||||
try {
|
||||
return (InitialContextFactory) icfClass.newInstance();
|
||||
return (InitialContextFactory) ReflectionUtils.accessibleConstructor(icfClass).newInstance();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Cannot instantiate specified InitialContextFactory: " + icf, ex);
|
||||
throw new IllegalStateException("Unable to instantiate specified InitialContextFactory: " + icf, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,7 @@ public abstract class ProfileValueUtils {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
profileValueSource = profileValueSourceType.newInstance();
|
||||
profileValueSource = ReflectionUtils.accessibleConstructor(profileValueSourceType).newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -366,17 +366,17 @@ class StubWebApplicationContext implements WebApplicationContext {
|
||||
|
||||
@Override
|
||||
public <T> T createBean(Class<T> beanClass) {
|
||||
return BeanUtils.instantiate(beanClass);
|
||||
return BeanUtils.instantiateClass(beanClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) {
|
||||
return BeanUtils.instantiate(beanClass);
|
||||
return BeanUtils.instantiateClass(beanClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) {
|
||||
return BeanUtils.instantiate(beanClass);
|
||||
return BeanUtils.instantiateClass(beanClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user