Skip to content

HttpServletResponse.setJavalinCookie can throw exception if there are no cookies #2308

@Jerbell

Description

@Jerbell

Actual behavior (the bug)
I'm getting this issue in AWS Lambda - so this wouldn't be very common. However, if there are no cookies and you try to set a cookie then currently you can get an exception.

Expected behavior
Run as expected.

To Reproduce
Don't have cookies and set a cookie. I didn't do a test, but can show the code to fix.

Additional context
https://github.com/javalin/javalin/blob/master/javalin/src/main/java/io/javalin/http/Cookie.kt#L90

cookies.removeFirstKt()?.let { first -> this.setHeader(Header.SET_COOKIE, first.addSameSite(javalinCookie)) }

should become:

cookies.removeFirstOrNull()?.let { first -> this.setHeader(Header.SET_COOKIE, first.addSameSite(javalinCookie)) }

The ?. implies that you expect this to not bomb out if the remove call returns null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions