Restore lenient null return value for ConditionContext.getBeanFactory()
Includes nullable return value for getClassLoader() with corresponding notes in applicable javadoc. Issue: SPR-16866
This commit is contained in:
parent
5bbeadec0c
commit
46a89d9534
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 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.
|
||||||
|
@ -89,7 +89,9 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
||||||
void setBeanClassLoader(@Nullable ClassLoader beanClassLoader);
|
void setBeanClassLoader(@Nullable ClassLoader beanClassLoader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return this factory's class loader for loading bean classes.
|
* Return this factory's class loader for loading bean classes
|
||||||
|
* (only {@code null} if even the system ClassLoader isn't accessible).
|
||||||
|
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
ClassLoader getBeanClassLoader();
|
ClassLoader getBeanClassLoader();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 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.
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context information for use by {@link Condition}s.
|
* Context information for use by {@link Condition}s.
|
||||||
|
@ -33,13 +34,17 @@ public interface ConditionContext {
|
||||||
/**
|
/**
|
||||||
* Return the {@link BeanDefinitionRegistry} that will hold the bean definition
|
* Return the {@link BeanDefinitionRegistry} that will hold the bean definition
|
||||||
* should the condition match.
|
* should the condition match.
|
||||||
|
* @throws IllegalStateException if no registry is available (which is unusual:
|
||||||
|
* only the case with a plain {@link ClassPathScanningCandidateComponentProvider})
|
||||||
*/
|
*/
|
||||||
BeanDefinitionRegistry getRegistry();
|
BeanDefinitionRegistry getRegistry();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link ConfigurableListableBeanFactory} that will hold the bean
|
* Return the {@link ConfigurableListableBeanFactory} that will hold the bean
|
||||||
* definition should the condition match.
|
* definition should the condition match, or {@code null} if the bean factory is
|
||||||
|
* not available (or not downcastable to {@code ConfigurableListableBeanFactory}).
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
ConfigurableListableBeanFactory getBeanFactory();
|
ConfigurableListableBeanFactory getBeanFactory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,8 +58,11 @@ public interface ConditionContext {
|
||||||
ResourceLoader getResourceLoader();
|
ResourceLoader getResourceLoader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link ClassLoader} that should be used to load additional classes.
|
* Return the {@link ClassLoader} that should be used to load additional classes
|
||||||
|
* (only {@code null} if even the system ClassLoader isn't accessible).
|
||||||
|
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
ClassLoader getClassLoader();
|
ClassLoader getClassLoader();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ class ConditionEvaluator {
|
||||||
return (List<String[]>) (values != null ? values : Collections.emptyList());
|
return (List<String[]>) (values != null ? values : Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Condition getCondition(String conditionClassName, ClassLoader classloader) {
|
private Condition getCondition(String conditionClassName, @Nullable ClassLoader classloader) {
|
||||||
Class<?> conditionClass = ClassUtils.resolveClassName(conditionClassName, classloader);
|
Class<?> conditionClass = ClassUtils.resolveClassName(conditionClassName, classloader);
|
||||||
return (Condition) BeanUtils.instantiateClass(conditionClass);
|
return (Condition) BeanUtils.instantiateClass(conditionClass);
|
||||||
}
|
}
|
||||||
|
@ -202,8 +202,8 @@ class ConditionEvaluator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public ConfigurableListableBeanFactory getBeanFactory() {
|
public ConfigurableListableBeanFactory getBeanFactory() {
|
||||||
Assert.state(this.beanFactory != null, "No ConfigurableListableBeanFactory available");
|
|
||||||
return this.beanFactory;
|
return this.beanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +218,8 @@ class ConditionEvaluator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public ClassLoader getClassLoader() {
|
public ClassLoader getClassLoader() {
|
||||||
Assert.state(this.classLoader != null, "No ClassLoader available");
|
|
||||||
return this.classLoader;
|
return this.classLoader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 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.
|
||||||
|
@ -72,7 +72,9 @@ public interface ResourceLoader {
|
||||||
* in a uniform manner with the ResourceLoader, rather than relying
|
* in a uniform manner with the ResourceLoader, rather than relying
|
||||||
* on the thread context ClassLoader.
|
* on the thread context ClassLoader.
|
||||||
* @return the ClassLoader
|
* @return the ClassLoader
|
||||||
|
* (only {@code null} if even the system ClassLoader isn't accessible)
|
||||||
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
|
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
|
||||||
|
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
ClassLoader getClassLoader();
|
ClassLoader getClassLoader();
|
||||||
|
|
Loading…
Reference in New Issue