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

+1 vote
in Java Interop by

It appears to be impossible to override Object.finalize() using proxy. If the method is defined using proxy, then it cannot be called straightforwardly (see below), and it is not called as a finalizer during normal program execution (not demonstrated below).

See extensive discussion at: https://groups.google.com/group/clojure/browse_thread/thread/a1e2fca45af6c1af

user=> (def m (proxy (link: java.util.HashMap) (link: )

    (finalize (link: )
      ;(proxy-super finalize)
      (prn "finalizing..."))
    (hashCode (link: )


user=> (.hashCode m)
user=> (.finalize m)
IllegalArgumentException No matching field found: finalize for class user.proxy$java.util.HashMap$0 clojure.lang.Reflector.getInstanceField (Reflector.java:289)

There is at least one of two bugs here (thanks to Cedric Greevey for summarising this way):

  • If the inability to override finalize() is unintentional, that's a bug.
  • If it's intentional for some reason, then (a) that's not documented, and (b) the failure is silent, in the sense that an explicit call produces an apparently completely unrelated error (above), and the failure to call the method during object finalization is completely silent.

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-911 (reported by alex+import)