babashka / process

Clojure library for shelling out / spawning sub-processes
Eclipse Public License 1.0
219 stars 29 forks source link

Exceptions when AOT compiled with Java 9+ and run with Java 8 #111

Closed mainej closed 1 year ago

mainej commented 1 year ago

I have some AOT compiled code which includes babashka.process. I've compiled (with Java 11, I think), but I have users who have Java 8. The AOT compiled code fails with exceptions related to using features that don't exist in Java 8. In my case, it's easy enough to ask my users to upgrade Java, so I have a workaround, but I thought I'd report the problem anyway.

babashka.process attempts to be compatible with different versions of the JDK with the if-before-jdk8 macro. But the macro isn't compatible with AOT compilation. When AOT compiled with Java 9+, the macro expands to the post-8 branch during compilation. This means that the post-8 branch will always execute, even if run with Java 8.

It's tempting to suggest adding a syntax-quote outside the (if (identical?..., so that the check happens at runtime, not compile time. But I don't think that's the only change that would be necessary. Several def and defn forms are wrapped in if-before-jdk8. To make the check happen at runtime, if-before-jdk8 would have to be moved inside those forms.

Edit: Understood if Java 8 support isn't something you want to spend time on. :)

borkdude commented 1 year ago

Indeed. If you intend to support jdk8, then AOT using jdk8.