Skip to content

fix: remove unnecessary cast#3150

Closed
mmoayyed wants to merge 1 commit into
spring-cloud:mainfrom
mmoayyed:patch-remove-cast
Closed

fix: remove unnecessary cast#3150
mmoayyed wants to merge 1 commit into
spring-cloud:mainfrom
mmoayyed:patch-remove-cast

Conversation

@mmoayyed

Copy link
Copy Markdown
Contributor

The cast here is unnecessary, and in some cases can cause a ClassCastException particularly when the environment created is a different type (as is the case with Spring Cloud Bootstrap)

Signed-off-by: Misagh Moayyed <mm1844@gmail.com>
@mmoayyed

Copy link
Copy Markdown
Contributor Author

Example failure:

java.lang.ClassCastException: class org.springframework.cloud.bootstrap.BootstrapApplicationListener$1 cannot be cast to class org.springframework.core.env.StandardEnvironment (org.springframework.cloud.bootstrap.BootstrapApplicationListener$1 and org.springframework.core.env.StandardEnvironment are in unnamed module of loader 'app')
	at org.springframework.cloud.stream.function.RoutingFunctionEnvironmentPostProcessor.postProcessEnvironment(RoutingFunctionEnvironmentPostProcessor.java:45)
	at org.springframework.boot.support.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:135)
	at org.springframework.boot.support.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:118)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:180)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:173)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:151)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
	at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:137)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$0(SpringApplicationRunListeners.java:66)
	at java.base/java.util.ImmutableCollections$List12.forEach(ImmutableCollections.java:681)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:123)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:355)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:154)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:198)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:180)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:173)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:151)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
	at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:137)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$0(SpringApplicationRunListeners.java:66)
	at java.base/java.util.ImmutableCollections$List12.forEach(ImmutableCollections.java:681)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:123)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:355)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:154)

@olegz olegz closed this in 77c5ed6 Oct 29, 2025
@AkashB23

Copy link
Copy Markdown

@olegz can we please include this fix into 4.3.x train aswell ? as the classcast excpetion is introduced in 4.3.1

olegz pushed a commit that referenced this pull request Jan 20, 2026
Signed-off-by: Misagh Moayyed <mm1844@gmail.com>

Resolves #3150
@olegz

olegz commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

@AkashB23 done

@AkashB23

Copy link
Copy Markdown

@AkashB23 done

Tq @olegz , when is 4.3.2 expected to be released ?

@AkashB23

Copy link
Copy Markdown

@olegz any updates with 4.3.2 patch with the above fix ? when is it planned to be released ?

@AkashB23

Copy link
Copy Markdown

@olegz I dont see the 4.3.2 release avaiable yet, its still with snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants