Skip to content

Regression in @Condition exclusion [SPR-12233] #16848

Closed
@spring-projects-issues

Description

@spring-projects-issues

Christopher Smith opened SPR-12233 and commented

I have a bean that's doing conditional autoconfiguration based on whether a certain property is available in the environment; the actual condition matcher is

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	return context.getEnvironment().containsProperty(POSTBACK_URL_PROPERTY);
}

The configuration class then creates a bean using an @Value injection if that property is present.

Spring 4.0.7->4.1.0 introduced a regression wherein the @Value is being evaluated even when the @Condition should not match, causing the context startup to crash. I have debugged, and Spring is in fact running the condition's matcher before proceeding to try (and fail) to extract the property from the environment. I attempted to step through it, but I could not tell whether the environment is erroneously returning true from containsProperty or the DI container is failing to disable the class when it has a false condition.

A simple Spring Boot application demonstrating the behavior is available at the GitHub link. Change the Spring version in the POM to 4.1.0 to demonstrate the bug; the launcher will crash on startup.


Affects: 4.1 GA

Reference URL: https://github.com/chrylis/spring-SPR-12233

Issue Links:

Referenced from: commits 4c59d85

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions