snowdrop-zen / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
1 stars 0 forks source link

RequestScoped beans keeping property values from previous requests when using kotlin. #130

Closed snowdrop-bot closed 4 years ago

snowdrop-bot commented 4 years ago

Describe the bug When using kotlin and injecting a RequestScoped bean, on each new request a new bean instance is initialized, but for some reason, the property values from the previous request bean are kept, this seems to be an issue only with the kotlin extension, because I couldn't reproduce the issue using Java.

Expected behavior The new request bean should not contain previous property values

Actual behavior A new bean instance is created on each request, but the same property values from previous requests are propagated.

To Reproduce I've created a project to reproduce the issue here: https://github.com/leandrobortoli/quarkus-issue-request-scoped

On each request, it checks if the bean property has been initialized and if not initializes it with a random value, as a result, we can see that only the first request initializes the properties and the values are propagated in the subsequent requests.

@Path("/ping")
class PingController {

    @Inject
    lateinit var requestScopedBean: RequestScopedBean

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    fun ping(): String {
        if(requestScopedBean.myProperty == null) {
            println("Setting requestScopedBean.myProperty")
            requestScopedBean.myProperty = java.util.Random().nextInt()
        }
        if(requestScopedBean.myStringProperty == null) {
            println("Setting requestScopedBean.myStringProperty")
            requestScopedBean.myStringProperty = StringUtils.randomString()
        }
        println("requestScopedBean ref: $requestScopedBean")
        println("requestScopedBean.myProperty: ${requestScopedBean.myProperty}")
        println("requestScopedBean.myStringProperty: ${requestScopedBean.myStringProperty}")
        return "pong"
    }
}
@RequestScoped
open class RequestScopedBean {

    var myProperty: Int? = null
    var myStringProperty: String? = null

    init {
        println("Initializing RequestScopedBean")
    }
}

Screenshots OUTPUT WITH 3 CONSECUTIVE REQUESTS: image

Environment (please complete the following information):


https://github.com/quarkusio/quarkus/issues/10290


$upstream:10290$