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

Spring Webflux, R2DBC: class cannot be cast to class kotlin.Result #33943

Open
msotho opened this issue Nov 22, 2024 · 2 comments
Open

Spring Webflux, R2DBC: class cannot be cast to class kotlin.Result #33943

msotho opened this issue Nov 22, 2024 · 2 comments
Assignees
Labels
theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression
Milestone

Comments

@msotho
Copy link

msotho commented Nov 22, 2024

Problem:
The below code throws the following error on Spring Boot 3.4.0 but not on Spring Boot 3.3.6:

java.lang.ClassCastException: class kotlin.Unit cannot be cast to class kotlin.Result (kotlin.Unit and kotlin.Result are in unnamed module of loader 'app')
interface Repo {
    suspend fun fetch(): Result<Unit>
}

@Repository
class RepoImpl : Repo {
    override suspend fun fetch(): Result<Unit> {
        return Result.success(Unit)
    }
}

@RestController
class HomeAPI(private val repo: Repo) {

    @GetMapping("/")
    suspend fun index(): ResponseEntity<Unit> {
        repo.fetch().getOrThrow()

        return ResponseEntity(HttpStatus.OK)
    }

}

More details:
This seems to occur when I add the spring-boot-starter-data-r2dbc related dependencies

Minimal Repo: https://github.com/msotho/castissue.git

Includes a Unit Test:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
internal class HomeAPITest @Autowired constructor(private val webTestClient: WebTestClient) {

    @Test
    fun `should return http status OK`() {
        webTestClient
            .get()
            .uri("/")
            .accept(MediaType.APPLICATION_JSON)
            .exchange()
            .expectStatus().isOk
    }

}
@msotho msotho changed the title Spring Webflux, R2DBC class cannot be cast to class kotlin.Result Spring Webflux, R2DBC: class cannot be cast to class kotlin.Result Nov 22, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 22, 2024
@wilkinsona
Copy link
Member

Thanks for the sample.

As far as I can tell, this is a regression in Spring Framework 6.2. The problem occurs with Spring Boot 3.3.6 when the Spring Framework version is overridden to 6.2.0:

ext {
    set("spring-framework.version", "6.2.0")
}

We'll transfer this issue so that the Framework team can continue the investigation.

@snicoll snicoll transferred this issue from spring-projects/spring-boot Nov 22, 2024
@msotho
Copy link
Author

msotho commented Nov 23, 2024

Setting Spring Boot 3.3.6 then it works. So it seems it's introduced by 3.4.0

@sdeleuze sdeleuze self-assigned this Nov 26, 2024
@sdeleuze sdeleuze added theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 26, 2024
@sdeleuze sdeleuze added this to the 6.2.1 milestone Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants