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

Javalin 6.1.0: java.lang.NoSuchMethodError: 'java.lang.Object java.util.List.removeFirst()' when setting a cookie #2117

Closed
Jerbell opened this issue Feb 22, 2024 · 14 comments

Comments

@Jerbell
Copy link
Contributor

Jerbell commented Feb 22, 2024

Actual behavior (the bug)
When I set a cookie I get a java.lang.NoSuchMethodError: 'java.lang.Object java.util.List.removeFirst()'. I have confirmed with a minimal project.

Expected behavior
Should be able to set a cookie.

To Reproduce

import io.javalin.Javalin
import io.javalin.http.Cookie

fun main() {
    val app = Javalin.create(/*config*/)
            .get("/") { ctx ->
                val cookie = Cookie("name", "value")
                cookie.isHttpOnly = true
                ctx.cookie(cookie)
                ctx.result("Hello World")
            }
            .start(7070)
}

Click on the URL once the server has started.

Additional context
This only happens with Javalin 6.1.0. I'm not sure why this happens. It's not clear, because the code looks like it should all work. Could the Kotlin version have been changed accidentally on compile?

@tipsy
Copy link
Member

tipsy commented Feb 22, 2024

Thanks @Jerbell - These NoSuchMethodError issues are usually caused by conflicting dependencies. The cookie API is well tested, so I don't think this is an actual bug. How have you configured your project?

@SentryMan
Copy link
Contributor

removeFirst was only added to java.util.List in JDK 21

@tipsy
Copy link
Member

tipsy commented Feb 22, 2024

removeFirst was only added to java.util.List in JDK 21

Would be very surprising if we were using it then 🤔

The removeFirst that we are using is this:

@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
public fun <T> MutableList<T>.removeFirst(): T = if (isEmpty()) throw NoSuchElementException("List is empty.") else removeAt(0)

@rob-bygrave
Copy link

As a guess without the background (or seeing the actual stack trace), with the maven-compiler-plugin / configuration instead of using source and target it could use release:

https://github.com/javalin/javalin/blob/master/pom.xml#L306-L307

So change from:

<configuration>
    <source>${jdk.version}</source>
    <target>${jdk.version}</target>
</configuration>

To:

<configuration>
    <release>${jdk.version}</release>
</configuration>

@tipsy
Copy link
Member

tipsy commented Feb 22, 2024

Oh, this is not fun... It's picking a new Java method instead of the Kotlin extension we're using? I could update the POM, but maybe it's safer to do import kotlin.collections.removeFirst as removeFirstKt.

@dzikoysk have you ran into this before?

@rob-bygrave
Copy link

rob-bygrave commented Feb 22, 2024

I could update the POM

We could do both. I'd suggest we really should be using release going forward (and not source and target).

@tipsy tipsy closed this as completed in 7799662 Feb 22, 2024
@tipsy
Copy link
Member

tipsy commented Feb 22, 2024

We could do both. I'd suggest we really should be using release going forward (and not source and target).

Did both in 7799662.

@dzikoysk
Copy link
Member

@dzikoysk have you ran into this before?

Yes, this is caused by your setup - you've released Javalin that is targeted for JDK11 with JDK21.

@tipsy
Copy link
Member

tipsy commented Feb 22, 2024

Yes, this is caused by your setup - you've released Javalin that is targeted for JDK11 with JDK21.

It seems like a pretty serious issue that all the Kotlin extensions can be hijacked by Java versions though... how do we guard against that in general?

@dzikoysk
Copy link
Member

dzikoysk commented Feb 22, 2024

Releasing a build from the minimal required Java version is enough to avoid this kind of issues. For instance, I've set the jdk version on CI to 11, but it looks like zug bumped it 4 days ago, so snapshots builds are also affected now 😬

@dzikoysk
Copy link
Member

The last time I faced this issue I kinda forgot about this, but maybe this time it might be a good idea to report this on YouTrack. They already have a few similar issues, but maybe we can somehow push them to prioritize a fix at some point:

@Jerbell
Copy link
Contributor Author

Jerbell commented Feb 23, 2024

Thanks everyone.
The stack trace was basically the same as the issue @dzikoysk has reported - in that it gave the impression it was trying to use the Kotlin method, but then complaining it wasn't there.
I was using Java 17.

tipsy added a commit that referenced this issue Feb 23, 2024
- import kotlin.collections.removeFirst as removeFirstKt
- Set <release> instead of <source> and <target>
- Downgrade JTE to 2x
tipsy added a commit that referenced this issue Feb 23, 2024
- import kotlin.collections.removeFirst as removeFirstKt
- Set <release> instead of <source> and <target>
- Downgrade JTE to 2x
tipsy added a commit that referenced this issue Feb 23, 2024
…to 3.3.0 (#2127)

* [context] Prevent unintended usage of JDK 21 feature (closes #2117)

- Import import kotlin.collections.removeFirst as removeFirstKt
- Set <release> instead of <source> and <target>

* [tests] Add more ApiBuilder tests

* [distribution] Revert 64ccbe1 and use JDK11 for snapshots GH-2117 (#2123)

* [deps]: Bump kotlin.version from 1.9.10 to 1.9.22 (#2128)

Bumps `kotlin.version` from 1.9.10 to 1.9.22.

Updates `org.jetbrains.kotlin:kotlin-stdlib-jdk8` from 1.9.10 to 1.9.22
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](JetBrains/kotlin@v1.9.10...v1.9.22)

Updates `org.jetbrains.kotlin:kotlin-reflect` from 1.9.10 to 1.9.22
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](JetBrains/kotlin@v1.9.10...v1.9.22)

Updates `org.jetbrains.kotlin:kotlin-stdlib-common` from 1.9.10 to 1.9.22
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](JetBrains/kotlin@v1.9.10...v1.9.22)

Updates `org.jetbrains.kotlin:kotlin-stdlib` from 1.9.10 to 1.9.22
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](JetBrains/kotlin@v1.9.10...v1.9.22)

Updates `org.jetbrains.kotlin:kotlin-maven-plugin` from 1.9.10 to 1.9.22

---
updated-dependencies:
- dependency-name: org.jetbrains.kotlin:kotlin-stdlib-jdk8
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: org.jetbrains.kotlin:kotlin-reflect
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: org.jetbrains.kotlin:kotlin-stdlib-common
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: org.jetbrains.kotlin:kotlin-stdlib
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: org.jetbrains.kotlin:kotlin-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [deps]: Bump org.apache.maven.plugins:maven-resources-plugin (#2129)

Bumps [org.apache.maven.plugins:maven-resources-plugin](https://github.com/apache/maven-resources-plugin) from 3.2.0 to 3.3.1.
- [Release notes](https://github.com/apache/maven-resources-plugin/releases)
- [Commits](apache/maven-resources-plugin@maven-resources-plugin-3.2.0...maven-resources-plugin-3.3.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-resources-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [deps]: Bump org.apache.maven.plugins:maven-source-plugin

Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.1 to 3.3.0.
- [Commits](apache/maven-source-plugin@maven-source-plugin-3.2.1...maven-source-plugin-3.3.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-source-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: tipsy <davidaase@hotmail.com>
Co-authored-by: dzikoysk <dzikoysk@dzikoysk.net>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
tipsy added a commit that referenced this issue Feb 23, 2024
* [context] Prevent unintended usage of JDK 21 feature (closes #2117)

- Import import kotlin.collections.removeFirst as removeFirstKt
- Set <release> instead of <source> and <target>

* [tests] Add more ApiBuilder tests

* [distribution] Revert 64ccbe1 and use JDK11 for snapshots GH-2117 (#2123)

* [deps]: Bump org.assertj:assertj-core from 3.25.0 to 3.25.3

Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.25.0 to 3.25.3.
- [Release notes](https://github.com/assertj/assertj/releases)
- [Commits](assertj/assertj@assertj-build-3.25.0...assertj-build-3.25.3)

---
updated-dependencies:
- dependency-name: org.assertj:assertj-core
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: tipsy <davidaase@hotmail.com>
Co-authored-by: dzikoysk <dzikoysk@dzikoysk.net>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@tipsy
Copy link
Member

tipsy commented Feb 23, 2024

@Jerbell please try 6.1.1 now :)

@Jerbell
Copy link
Contributor Author

Jerbell commented Feb 24, 2024

Thanks - tis working now

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

No branches or pull requests

5 participants