Comments (8)
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.
Yes, that is definitely it.
from babashka.
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.
Btw, note that (long x)
does work.
from babashka.
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.
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.
Thanks! 😄
from babashka.
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)
- `Thread/setDefaultUncaughtExceptionHandler` compiles but is ignored HOT 2
- Expose sci.core in bb
- Consider bake in camel-snake-kebab
- clojure.java.broswe/browse-url truncates URLs with multiple query parameters on Windows HOT 2
- Port CircleCI macOS x64 Intel builds to M1 runner + Rosetta before October HOT 1
- Babashka does not propagate error code when running a task that doesn't exist within another task HOT 1
- Asahi Linux - Native ARM Linux on Apple M1/M2/M3 HOT 10
- require should throw FileNotFoundException when namespace isn't found
- Support for java.util Timer and TimerTask HOT 4
- cider-macroexpand-1 not working HOT 1
- Include ns `babashka.http-client.websocket`
- StackOverflowError using reduce HOT 2
- InvocationTargetException with java.net.http.HttpClient on v1.2+ HOT 17
- Source releases miss submodule dependencies HOT 3
- Var `*file*` should work like `__FILE__` in C HOT 1
- Method readPassword on class java.io.ProxyingConsole not allowed! HOT 2
- Async AWS queries using grzm/awyeah-api occasionally throws java.util.NoSuchElementException HOT 2
- StackOverflowError on 1.3.186 but script properly working with 1.3.185 HOT 6
- `str/join` doesn't work in `bb.edn` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babashka.