Giter Club home page Giter Club logo

Comments (8)

borkdude avatar borkdude commented on May 26, 2024 1

maybe an alternative more specific but trivial fix could be to explicitly add a cast (long ms) inbabashka.impl.clojure.core.async/timeout

For sure, we can do this.

The other issue may not be as easily fixable. The Clojure compiler will emit a byte code operation to cast a java.lang.* boxed object to a primitive and will then invoke the method on the primitive, but since babashka is basically using clojure.lang.Reflector it works similarly when using reflection in Clojure.

from babashka.

borkdude avatar borkdude commented on May 26, 2024 1

Yes, that is definitely it.

from babashka.

borkdude avatar borkdude commented on May 26, 2024

methods are resolved through reflection. See sci.impl.reflector which is largely based on clojure/lang/Reflector.java. A similar thing happens in clj when using reflection:

 $ clj
Clojure 1.10.3
user=> (type (int 1))
java.lang.Integer
user=> (def x (int 1))
#'user/x
user=> (type x)
java.lang.Integer
user=> (Thread/sleep x)
Execution error (IllegalArgumentException) at user/eval5 (REPL:1).
No matching method sleep found taking 1 args

from babashka.

borkdude avatar borkdude commented on May 26, 2024

Btw, note that (long x) does work.

from babashka.

Cortys avatar Cortys commented on May 26, 2024

Interesting. Your example with the indirection through the x variable works for me when using JVM 17 but indeed throws when using JVM 20 (tested using Clojure 1.10.3 and Clojure 1.11.1). Not sure what's going on here.

As far as I can tell the method is correctly resolved in any case if a type hint is used:

(def x (int 1))
(Thread/sleep ^int x) ;; works on JVM 17 and 20

In Java, both long and int arguments are supported as well:

int x = 1000;
Thread.sleep(x); // works on JVM 17 and 20

I also just checked that the example from my first post ((Thread/sleep (int 1000))) worked in Babashka v1.1.173 but no longer works since v1.2.174.

Of course, I agree that this issue is easy to circumvent in ones own code. The reason I initially noticed this bug was due to this line of code in the throttler library (which in turn calls Thread/sleep here), which I use in one of my BB scripts and which stopped working after an update of BB.

While the specific issue I encountered is easy to fix/circumvent (e.g., by forking throttler or, as a quick-and-dirty solution, by altering the var roots of the affected functions at runtime in userland), the change of behaviour introduced in v1.2.174 could maybe cause other unforeseen incompatibilities with other Clojure libraries that worked previously with Babashka.

If this issue turns out to be not easily fixable, maybe an alternative more specific but trivial fix could be to explicitly add a cast (long ms) inbabashka.impl.clojure.core.async/timeout implementation.

from babashka.

Cortys avatar Cortys commented on May 26, 2024

Ah ok, I see, that makes sense.

Just out of curiosity, do you have an idea, what might have caused the difference in behaviour from BB v1.1.173 to v.1.2.174? Maybe the upgrade from Java 11 to 19?

from babashka.

Cortys avatar Cortys commented on May 26, 2024

Thanks! 😄

from babashka.

borkdude avatar borkdude commented on May 26, 2024

A better fix underway as part of issue #1513. Will be fixed in next release, everything will just work for Thread/sleep

from babashka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.