Closed
Description
Andrzej Leśkiewicz opened SPR-17606 and commented
I encountered strange bug with regard to handling of Profile
conditions and active profiles. Below is a table describing tested combinations and expected results
@Profile value |
Active profiles | Expected result | Actual result |
---|---|---|---|
!a & b | b | true | true |
b & !a | b | true | true |
!a & b | a | false | true |
b & !a | a | false | false |
!a & b | ab | false | false |
b & !a | ab | false | false |
As shown in the table above, test notAandBShouldNotAcceptWhenAActive should not accept the bean, but it does, and just different order of operations in @Profile
is enough to behave accordingly. Tests were performed on JDK8. I created simple project to verify it and linked it with this issue.
Junit test ot reproduce is as follows:
@Test
public void notAandBShouldNotAcceptWhenAActive() throws Exception {
// given
Profiles notAAndB = Profiles.of("!a & b");
AbstractEnvironment environment = new MockEnvironment();
environment.setActiveProfiles("a");
// when
boolean acceptsProfiles = environment.acceptsProfiles(notAAndB);
// then
assertThat(acceptsProfiles).isFalse();
}
Affects: 5.1.3
Reference URL: https://github.com/aleskiewicz/spring-profiles-operators-test
Issue Links:
- Support AND operator in @Profile annotation [SPR-12458] #17063 Support AND operator in
@Profile
annotation