Description

When using Spring Boot version 3.3.4 with the dependency management plugin io.spring.dependency-management version 1.1.6, it installs spring-cloud-stream:4.1.3, which includes the package org.springframework.cloud:spring-cloud-function-context:4.1.3.

The version 4.1.3 of the package spring-cloud-function-context creates issues when consuming messages from the stream. It appears to load into two classloaders: "app" and "bootstrap". However, the previous version org.springframework.cloud:spring-cloud-function-context:4.1.2 does not exhibit this issue.

This issue took a considerable amount of time to debug.

Steps to Reproduce

  1. Set up a Spring Boot project with version 3.3.4.
  2. Use the dependency management plugin with ID io.spring.dependency-management version 1.1.6.
  3. Ensure that spring-cloud-stream:4.1.3 is included in the dependencies.
  4. Attempt to consume messages from a stream.

Expected Behavior

The package org.springframework.cloud:spring-cloud-function-context:4.1.3 should function without causing issues related to classloaders "app" and "bootstrap" when consuming messages from the stream.

Actual Behavior

The package org.springframework.cloud:spring-cloud-function-context:4.1.3 loads into two classloaders: "app" and "bootstrap", causing issues when consuming messages from the stream.

Workaround

Downgrading to org.springframework.cloud:spring-cloud-function-context:4.1.2 resolves the issue.

Environment

  • Spring Boot Version: 3.3.4
  • Dependency Management Plugin: io.spring.dependency-management version 1.1.6
  • Affected Package: org.springframework.cloud:spring-cloud-function-context:4.1.3
  • Working Package Version: org.springframework.cloud:spring-cloud-function-context:4.1.2

Additional Context

plugins {
    id "java"
    id "org.springframework.boot" version "3.3.4"
    id "io.spring.dependency-management" version "1.1.6"
}
dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:2023.0.3"
    }
}
dependencies {
    implementation "org.springframework.boot:spring-boot-starter"
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.cloud:spring-cloud-stream'
    implementation 'org.springframework.cloud:spring-cloud-starter-stream-kafka'
}

Logs

Caused by: java.lang.ClassCastException: class [B cannot be cast to class <your class> ([B is in module java.base of loader 'bootstrap'; <your class> is in unnamed module of loader 'app')

Comment From: wilkinsona

Thanks for the report. You seem to have identified that the problem occurs with org.springframework.cloud:spring-cloud-function-context:4.1.3 but does not occur with org.springframework.cloud:spring-cloud-function-context:4.1.2. As such, it would appear to be a regression in Spring Cloud Function 4.1.3.

Spring Cloud Function is managed as a separate project. If want to pursue this, I would recommend creating a complete yet minimal sample that reproduces the ClassCastException as the information provided above isn't sufficient to diagnose the problem. Once you have this sample, you could open a Spring Cloud Function issue and ask the maintainers to take a look at it.