Browse Source

Restore lenient null return value for ConditionContext.getBeanFactory()

Includes nullable return value for getClassLoader() with corresponding notes in applicable javadoc.

Issue: SPR-16866
pull/1842/head
Juergen Hoeller 8 years ago
parent
commit
46a89d9534
  1. 6
      spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
  2. 14
      spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java
  3. 6
      spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java
  4. 4
      spring-core/src/main/java/org/springframework/core/io/ResourceLoader.java

6
spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -89,7 +89,9 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single @@ -89,7 +89,9 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
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
ClassLoader getBeanClassLoader();

14
spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -20,6 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
/**
* Context information for use by {@link Condition}s.
@ -33,13 +34,17 @@ public interface ConditionContext { @@ -33,13 +34,17 @@ public interface ConditionContext {
/**
* Return the {@link BeanDefinitionRegistry} that will hold the bean definition
* should the condition match.
* @throws IllegalStateException if no registry is available (which is unusual:
* only the case with a plain {@link ClassPathScanningCandidateComponentProvider})
*/
BeanDefinitionRegistry getRegistry();
/**
* 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();
/**
@ -53,8 +58,11 @@ public interface ConditionContext { @@ -53,8 +58,11 @@ public interface ConditionContext {
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();
}

6
spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java

@ -120,7 +120,7 @@ class ConditionEvaluator { @@ -120,7 +120,7 @@ class ConditionEvaluator {
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);
return (Condition) BeanUtils.instantiateClass(conditionClass);
}
@ -202,8 +202,8 @@ class ConditionEvaluator { @@ -202,8 +202,8 @@ class ConditionEvaluator {
}
@Override
@Nullable
public ConfigurableListableBeanFactory getBeanFactory() {
Assert.state(this.beanFactory != null, "No ConfigurableListableBeanFactory available");
return this.beanFactory;
}
@ -218,8 +218,8 @@ class ConditionEvaluator { @@ -218,8 +218,8 @@ class ConditionEvaluator {
}
@Override
@Nullable
public ClassLoader getClassLoader() {
Assert.state(this.classLoader != null, "No ClassLoader available");
return this.classLoader;
}
}

4
spring-core/src/main/java/org/springframework/core/io/ResourceLoader.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -72,7 +72,9 @@ public interface ResourceLoader { @@ -72,7 +72,9 @@ public interface ResourceLoader {
* in a uniform manner with the ResourceLoader, rather than relying
* on the thread context 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#forName(String, ClassLoader)
*/
@Nullable
ClassLoader getClassLoader();

Loading…
Cancel
Save