clojure-dev

borkdude 2024-09-30T19:00:36.623039Z

Found an issue in clojure 1.12 which I thought was fixed due to Reflector.java changes, but it seems not (yet)

$ JAVA_HOME=~/Downloads/graalvm-jdk-17.0.12+8.1/Contents/Home clj
Clojure 1.12.0
user=> (/ 1 200)
1/200
user=>  (Thread/sleep (/ 1 200))
nil
user=>
$ JAVA_HOME=~/Downloads/graalvm-jdk-22.0.1+8.1/Contents/Home clj
Clojure 1.12.0
user=> (/ 1 200)
1/200
user=>  (Thread/sleep (/ 1 200))
Execution error (IllegalArgumentException) at user/eval3 (REPL:1).
No matching method sleep found taking 1 args

2024-09-30T19:04:53.786849Z

It was supposed to fix (Thread/sleep 0.005) ?

borkdude 2024-09-30T19:05:26.795809Z

Also no:

user=> (Thread/sleep 0.005)
Execution error (IllegalArgumentException) at user/eval5 (REPL:1).
No matching method sleep found taking 1 args

2024-09-30T19:06:54.624409Z

No i meant, I was under the impression that something was fixed at some point relating to something that changed in java related to longs/ints passed to Thread/sleep, but does that also imply it's supposed to do something with floats/doubles? I might be thinking of something different than you're referring to.

borkdude 2024-09-30T19:08:07.087529Z

could be... at least, code that used to work in JDK 17 now doesn't work anymore in JDK19+ which was the more general problem here which lead to Reflector changes

borkdude 2024-09-30T19:08:42.719999Z

this one I believe: https://github.com/clojure/clojure/commit/3e2bfe64fd111323944ad98e9150898d893d74d1

borkdude 2024-09-30T19:10:00.619449Z

The tests in that patch do work, but there's more cases that did work in JDK17

2024-09-30T19:15:50.867379Z

So in jdk 17 it rounded the ms to sleep for to zero there? Or 1? Wouldn't have expected either really. Since at some point it would have to turn into a call to Thread/sleep(long millis), right?

borkdude 2024-09-30T19:18:35.835979Z

yeah, I think there would be a cast inserted somewhere. not sure if this was defined behavior but I got similar error reports for bb when migrating to JDK19+ which I fixed using a workaround

2024-09-30T19:19:31.923819Z

I guess thinking about it as (long (/ 1 200)) makes a bit more sense than "rounding". Sorry for the side track, just was curious

borkdude 2024-09-30T19:21:56.636629Z

I don't disagree necessarily, just wondering myself too

2024-09-30T19:22:52.114689Z

It is because java added a new overload on sleep

Alex Miller (Clojure team) 2024-09-30T19:27:31.283869Z

You now have a ratio, and two signatures and it matches neither

2024-09-30T19:27:50.795539Z

The changes in clojure above are about adjusting how the reflector handles widening and boxing, being able to pass a boxed Integer to a method that takes a primitive long

borkdude 2024-09-30T19:28:56.175639Z

yes, makes sense. I'll just tell people to change their scripts in bb then and I'll remove the workaround that I had in place pre 1.12, as their code would now also crash with 1.12

Alex Miller (Clojure team) 2024-09-30T19:28:56.870519Z

Clojure does cast in these situations when there is one signature, but the target has changed

borkdude 2024-09-30T19:31:32.231999Z

Ah I see the original issue wasn't even about these non-long-ish types: https://github.com/babashka/babashka/issues/1619, just about Integer, so yes, this is fixed in 1.12. Thanks all!

👍 1