Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
Reflection does not return the same order of methods across JVM invocations (via Class::getMethods). This is probably most apparent when submitting Clojure functions, which are Callable and Runnable, into an executor:


(ns repro)

;;(set! *warn-on-reflection* true)

(defn repro
  []
  (let [exec (java.util.concurrent.ForkJoinPool/commonPool)
        work #(do 1)]
    (deref (.submit ^Object exec work))))  ;; intentionally reflect

(defn -main []
   ;; dereffing a runnable returns nil, a callable can return a value, in this case an integer
  (System/exit (or (repro) 0)))



nondeterministic ➜ while true; do clojure -m repro; echo $?; done
0
0
0
1
0
0
0
1
0
0
0

5 Answers

0 votes
by

Comment made by: gshayban

attached a patch that sorts seen methods

0 votes
by

Comment made by: gshayban

re patch: the comparator's first pass (examining the arity) can disappear: only identical arity methods get compared. Does that sound right?

0 votes
by

Comment made by: bronsa

Yeah, that sounds right to me

0 votes
by

Comment made by: gshayban

patch with a more minimal comparator

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2413 (reported by gshayban)
...