Clojure

Non-deterministic method selection during reflection

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Triaged

Description

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
  1. CLJ-2413.patch
    25/Nov/18 5:36 PM
    3 kB
    Ghadi Shayban
  2. CLJ-2413-2.patch
    26/Nov/18 11:42 AM
    3 kB
    Ghadi Shayban

Activity

Hide
Ghadi Shayban added a comment -

attached a patch that sorts seen methods

Show
Ghadi Shayban added a comment - attached a patch that sorts seen methods
Hide
Ghadi Shayban added a comment -

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

Show
Ghadi Shayban added a comment - re patch: the comparator's first pass (examining the arity) can disappear: only identical arity methods get compared. Does that sound right?
Hide
Nicola Mometto added a comment -

Yeah, that sounds right to me

Show
Nicola Mometto added a comment - Yeah, that sounds right to me
Hide
Ghadi Shayban added a comment -

patch with a more minimal comparator

Show
Ghadi Shayban added a comment - patch with a more minimal comparator

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: