Clojure

(compile) crashes with NullPointerException if public function 'load' is defined

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: Release 1.4
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    Linux, OpenJDK 1.6.0 64bit

Description

When performing AOT compilation, if the namespace being compiled or one of the namespaces :required by it defines a public function named 'load', the compiler will crash with a NullPointerException.

The following code demonstrates this:

(ns ca.ancilla.kessler.core (:gen-class)) (defn load [x] x) (defn -main [& args] 0)

When run directly, with 'clojure -m ca.ancilla.kessler.core' or 'clojure ca/ancilla/kessler/core.clj', it runs as expected. When loaded with 'clojure -i' and (compile)d, however, or when automatically compiled by 'lein run', it results in a NullPointerException (the complete stack trace is attached).

This occurs whether or not 'load' or actually called. It does not, however, occur if 'load' is private.

Activity

Hide
Ben Kelly added a comment -

So, just to make sure that I have this right, then...

If I want to create a namespace with a public function that shares a name with a function in clojure.core, the only supported way of doing this is to (:refer-clojure :exclude [list of all such functions])?

If so, it would be nice if the warning were replaced with an error, rather than having the compiler emit an error and then crash.

Show
Ben Kelly added a comment - So, just to make sure that I have this right, then... If I want to create a namespace with a public function that shares a name with a function in clojure.core, the only supported way of doing this is to (:refer-clojure :exclude [list of all such functions])? If so, it would be nice if the warning were replaced with an error, rather than having the compiler emit an error and then crash.
Hide
Stuart Halloway added a comment -

You should not replace functions in clojure.core. This is left legal (with a loud CONSOLE warning) for compatibility, but programs that do it are in error.

Show
Stuart Halloway added a comment - You should not replace functions in clojure.core. This is left legal (with a loud CONSOLE warning) for compatibility, but programs that do it are in error.
Hide
Ben Kelly added a comment -

If you add (:refer-clojure :exclude [load]) to the (ns), it works fine:

(ns ca.ancilla.kessler.core (:refer-clojure :exclude [load]) (:gen-class))
(defn load [x] x)
(defn -main [& args] 0)

Thanks to llasram on IRC for discovering this.

Show
Ben Kelly added a comment - If you add (:refer-clojure :exclude [load]) to the (ns), it works fine: (ns ca.ancilla.kessler.core (:refer-clojure :exclude [load]) (:gen-class)) (defn load [x] x) (defn -main [& args] 0) Thanks to llasram on IRC for discovering this.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: