Skip to content

Instantly share code, notes, and snippets.

@fogus
Last active September 1, 2026 18:40
Show Gist options
  • Select an option

  • Save fogus/7dddbc82a4fb97058b17407aa371f356 to your computer and use it in GitHub Desktop.

Select an option

Save fogus/7dddbc82a4fb97058b17407aa371f356 to your computer and use it in GitHub Desktop.
(ns build
(:require [clojure.tools.build.api :as b]))
(def class-dir "target/classes")
(def java-src-dirs ["src/java"])
(def clj-src-dirs ["src/clj"])
(defn- basis [opts]
(b/create-basis {:aliases (:aliases opts)}))
(defn clean [_]
(b/delete {:path class-dir}))
(defn compile-java
[opts]
(b/javac {:src-dirs java-src-dirs
:class-dir class-dir
:basis (basis opts)
:javac-opts ["--release" "11"]}))
(defn compile-clj
[opts]
(b/compile-clj {:basis (basis opts)
:class-dir class-dir
:src-dirs clj-src-dirs
:ns-compile '[isf.genned]}))
(defn compile-all
[opts]
(compile-java opts)
(compile-clj opts))
package isf;
public interface CLJTestInterface {
public static String staticGreet(String s) {
return "static:" + s;
}
public static String staticGreetToAlias(String s) {
return "static with alias:" + s;
}
}
{:paths ["src/clj" "target/classes"]
:aliases
{:prepatch {:override-deps {org.clojure/clojure {:mvn/version "1.12.5"}}}
:patched {:override-deps {org.clojure/clojure {:mvn/version "1.12.6-alpha1"}}}
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
:ns-default build}}}
(ns isf.genned
(:gen-class :name isf.Genned
:implements [isf.CLJTestInterface]
:prefix "-"
:methods [
^{:static true} [staticGreetToAlias [String] void]
]))
(defn -staticGreetToAlias [s]
(println "forwarded! " s))
(import 'isf.CLJTestInterface)
(CLJTestInterface/staticGreet "foo")
(CLJTestInterface/staticGreetToAlias "foo")
(import 'isf.Genned)
(def g (Genned.))
(.staticGreet g "bar")
;; PREPATCH YOU"LL SEE
;; java.lang.NoSuchFieldError:
;; Class isf.Genned does not have member field
;; 'clojure.lang.Var staticGreet__var'
;;
;; WHY: gen-class's var-field-generation pass (`non-private-methods`)
;; filters OUT static methods when deciding which `__var` fields to
;; declare on the class, but the forwarder-generation pass
;; doesn't filter them out. The emitted staticGreet method body
;; still does `getstatic staticGreet__var`, referencing a field that
;; was never declared. The class is internally inconsistent.
;; POST-PATCH YOU'LL SEE
;; java.lang.IllegalArgumentException:
;; No matching method staticGreet found taking 1 args for class isf.Genned
(.staticGreetToAlias g "bar")
;; PREPATCH YOU"LL SEE
;; Unhandled clojure.lang.ArityException
;; Wrong number of args (2) passed to: isf.genned/-staticGreetToAlias
;; POST-PATCH YOU'LL SEE
;; java.lang.IllegalArgumentException:
;; No matching method staticGreetToAlias found taking 1 args for class isf.Genned
(Genned/staticGreet "bar")
;; BOTH
;; java.lang.IllegalArgumentException
;; No matching method staticGreet found taking 1 args for class isf.Genned
(Genned/staticGreetToAlias "bar")
;; BOTH pre and patched
;; forwarded! bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment