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

NPE when @ConditionalOnBean is present alongside with the @MessagingGateway #3374

Closed
shyding opened this issue Sep 2, 2020 · 2 comments · Fixed by #3378
Closed

NPE when @ConditionalOnBean is present alongside with the @MessagingGateway #3374

shyding opened this issue Sep 2, 2020 · 2 comments · Fixed by #3378

Comments

@shyding
Copy link

shyding commented Sep 2, 2020

For example:

5.2.x and above

Describe the bug

In Spring Boot application we declare like this:

	@ConditionalOnBean(name = "foo")
	@MessagingGateway
	public interface ConditionalGateway {

		void testGateway(Object payload);

	}

and get an excpetion at start up:

	at com.example.demo.DemoApplication.main(DemoApplication.java:13) [classes/:na]
Caused by: java.lang.IllegalStateException: Error processing condition on com.example.demo.DemoApplication$ConditionalGateway
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:90) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:71) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isConditionMatch(ClassPathScanningCandidateComponentProvider.java:513) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:496) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	... 22 common frames omitted
Caused by: java.lang.NullPointerException: null
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.containsBean(OnBeanCondition.java:288) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:197) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:119) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
@shyding shyding added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Sep 2, 2020
@artembilan
Copy link
Member

Please, start from StackOverflow and share as much info as possible. Some code to reproduce would be very useful.

We don't handle question here on GH and your description doesn't depict the problem.

Thanks for understanding.

@artembilan artembilan added status: invalid Not reproducable or not relevant to the current state of the project and removed status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Sep 8, 2020
@artembilan
Copy link
Member

OK. I decided to play with this and realized that issue is like this:

Caused by: java.lang.IllegalStateException: Error processing condition on com.example.demo.DemoApplication$ConditionalGateway
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:90) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:71) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isConditionMatch(ClassPathScanningCandidateComponentProvider.java:513) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:496) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	... 22 common frames omitted
Caused by: java.lang.NullPointerException: null
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.containsBean(OnBeanCondition.java:288) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:197) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:119) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]

So, the @ConditionalOnBean indeed doesn't work with the @MessagingGateway...

@artembilan artembilan changed the title why The @conditionalonbean annotation does not work on the @messaginggateway class ? NPE when @ConditionalOnBean is present alongside with the @MessagingGateway Sep 9, 2020
@artembilan artembilan reopened this Sep 9, 2020
@artembilan artembilan added backport 5.2.x in: core type: bug and removed status: invalid Not reproducable or not relevant to the current state of the project labels Sep 9, 2020
@artembilan artembilan added this to the 5.4 M3 milestone Sep 9, 2020
artembilan added a commit to artembilan/spring-integration that referenced this issue Sep 9, 2020

Verified

This commit was signed with the committer’s verified signature.
bnjmnt4n Benjamin Tan
Fixes spring-projects#3374

An internal `ClassPathScanningCandidateComponentProvider` instance in the `IntegrationComponentScanRegistrar`
does not propagate a provided `registry`.

* Implement `getRegistry()` on the internal `ClassPathScanningCandidateComponentProvider` to propagate
a provided into the `registerBeanDefinitions()` a `BeanDefinitionRegistry`
* Add `@Conditional` on some scanned `@MessagingGateway` in the `EnableIntegrationTests`

**Cherry-pick to 5.3.x & 5.2.x**
garyrussell pushed a commit that referenced this issue Sep 11, 2020

Verified

This commit was signed with the committer’s verified signature.
bnjmnt4n Benjamin Tan
* GH-3374: Fix scan for BF propagation

Fixes #3374

An internal `ClassPathScanningCandidateComponentProvider` instance in the `IntegrationComponentScanRegistrar`
does not propagate a provided `registry`.

* Implement `getRegistry()` on the internal `ClassPathScanningCandidateComponentProvider` to propagate
a provided into the `registerBeanDefinitions()` a `BeanDefinitionRegistry`
* Add `@Conditional` on some scanned `@MessagingGateway` in the `EnableIntegrationTests`

**Cherry-pick to 5.3.x & 5.2.x**

* * Remove unused import

* Restore `unused` warning on the unused registry arg
garyrussell pushed a commit that referenced this issue Sep 11, 2020

Verified

This commit was signed with the committer’s verified signature.
bnjmnt4n Benjamin Tan
* GH-3374: Fix scan for BF propagation

Fixes #3374

An internal `ClassPathScanningCandidateComponentProvider` instance in the `IntegrationComponentScanRegistrar`
does not propagate a provided `registry`.

* Implement `getRegistry()` on the internal `ClassPathScanningCandidateComponentProvider` to propagate
a provided into the `registerBeanDefinitions()` a `BeanDefinitionRegistry`
* Add `@Conditional` on some scanned `@MessagingGateway` in the `EnableIntegrationTests`

**Cherry-pick to 5.3.x & 5.2.x**

* * Remove unused import

* Restore `unused` warning on the unused registry arg
garyrussell pushed a commit that referenced this issue Sep 11, 2020

Verified

This commit was signed with the committer’s verified signature.
bnjmnt4n Benjamin Tan
* GH-3374: Fix scan for BF propagation

Fixes #3374

An internal `ClassPathScanningCandidateComponentProvider` instance in the `IntegrationComponentScanRegistrar`
does not propagate a provided `registry`.

* Implement `getRegistry()` on the internal `ClassPathScanningCandidateComponentProvider` to propagate
a provided into the `registerBeanDefinitions()` a `BeanDefinitionRegistry`
* Add `@Conditional` on some scanned `@MessagingGateway` in the `EnableIntegrationTests`

**Cherry-pick to 5.3.x & 5.2.x**

* * Remove unused import

* Restore `unused` warning on the unused registry arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants