Jakub Gwóźdź
07/08/2025, 2:13 PMimport java.net.http.HttpClient
fun main() {
val client: HttpClient = HttpClient.newHttpClient()
client.close()
}
Nothing suspicious here, usual code, right?
4. Run main.kt (from IntelliJ, or via ./amper run
00:01.810 INFO :autocloseable:compileJvm Compiling module 'autocloseable' for platform 'jvm'...
00:02.974 ERROR :autocloseable:compileJvm e: file:///Users/jakub.g/personal/jakub-gwozdz/autocloseable/src/main.kt:5:12 Unresolved reference 'close'.
ERROR: Task ':autocloseable:compileJvm' failed: Kotlin compilation failed:
e: file:///Users/jakub.g/personal/jakub-gwozdz/autocloseable/src/main.kt:5:12 Unresolved reference 'close'.
16:08:04: Execution finished 'run -m autocloseable --main-class MainKt'.
How. How is it possible that <http://java.net|java.net>.http.HttpClient
, which obviously is AutoCloseable
, yields this error for me?
Someone please confirm or deny this 🙂utikeev
07/08/2025, 2:22 PMHttpClient
becoming AutoCloseable
only since Java 21 while Amper uses Java 17 as the default JVM release version .
settings:
jvm:
release: 21
should do the trick 🙂
We'll discuss the default here a bit more, thanks for bringing it up!Jakub Gwóźdź
07/08/2025, 2:24 PMJakub Gwóźdź
07/08/2025, 2:41 PMutikeev
07/08/2025, 2:45 PMHttpClient.close
not being reported as incorrect API usage even in projects under other build systems. I have filed an issue about that:
IDEA-375650utikeev
07/08/2025, 3:02 PMsuresh
07/10/2025, 4:36 AMutikeev
07/10/2025, 11:30 AMkotlin.languageVersion
to 2.2
, but they aren't guaranteed to work the same way as they do in Kotlin 2.2.0.