Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Profile mishandles "not" operand mixed with "&" [SPR-17606] #22138

spring-projects-issues opened this issue Dec 18, 2018 · 2 comments

@Profile mishandles "not" operand mixed with "&" [SPR-17606] #22138

spring-projects-issues opened this issue Dec 18, 2018 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented Dec 18, 2018

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: 

public void notAandBShouldNotAcceptWhenAActive() throws Exception {
    // given
    Profiles notAAndB = Profiles.of("!a & b");
    AbstractEnvironment environment = new MockEnvironment();
    // when
    boolean acceptsProfiles = environment.acceptsProfiles(notAAndB);
    // then

Affects: 5.1.3

Reference URL:

Issue Links:

  • #17063 Support AND operator in @Profile annotation

Referenced from: pull request #2066, and commits 952045c

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 7, 2019

Juergen Hoeller commented

Stéphane Nicoll, Phil Webb, could you have a look at the associated pull request, please? It generally looks sensible to me; I'm just wondering whether I'm missing some original design decision in the profiles expression support...

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 8, 2019

Juergen Hoeller commented

Merged into master now. Thanks for the pull request!

If there is anything to follow up on, let's do it on master directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants