Skip to content

Commit 8446fd1

Browse files
committed
added assertions for correct postProcess invocation order
1 parent 5f9b2db commit 8446fd1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
8282

8383
private boolean postProcessBeanDefinitionRegistryCalled = false;
8484

85+
private boolean postProcessBeanFactoryCalled = false;
86+
8587

8688
/**
8789
* Set the {@link SourceExtractor} to use for generated bean definitions
@@ -128,6 +130,14 @@ public int getOrder() {
128130
* Derive further bean definitions from the configuration classes in the registry.
129131
*/
130132
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
133+
if (this.postProcessBeanDefinitionRegistryCalled) {
134+
throw new IllegalStateException(
135+
"postProcessBeanDefinitionRegistry already called for this post-processor");
136+
}
137+
if (this.postProcessBeanFactoryCalled) {
138+
throw new IllegalStateException(
139+
"postProcessBeanFactory already called for this post-processor");
140+
}
131141
this.postProcessBeanDefinitionRegistryCalled = true;
132142
processConfigBeanDefinitions(registry);
133143
}
@@ -137,6 +147,11 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
137147
* by replacing them with CGLIB-enhanced subclasses.
138148
*/
139149
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
150+
if (this.postProcessBeanFactoryCalled) {
151+
throw new IllegalStateException(
152+
"postProcessBeanFactory already called for this post-processor");
153+
}
154+
this.postProcessBeanFactoryCalled = true;
140155
if (!this.postProcessBeanDefinitionRegistryCalled) {
141156
// BeanDefinitionRegistryPostProcessor hook apparently not supported...
142157
// Simply call processConfigBeanDefinitions lazily at this point then.

0 commit comments

Comments
 (0)