Details
-
Type:
Defect
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: Release 1.3
-
Component/s: None
-
Labels:None
-
Patch:Code and Test
-
Approval:Ok
Description
This is really a request for improved error handling. If you use (alias) with a namespace that is not known it throws an NPE with imho a confusing error message.
Example:
user=> (alias 'R 'S)
java.lang.NullPointerException: Expecting Symbol + Namespace (NO_SOURCE_FILE:0)
user=> (.printStackTrace *e)
nil
user=> java.lang.NullPointerException: Expecting Symbol + Namespace (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:5348)
at clojure.lang.Compiler.eval(Compiler.java:5300)
at clojure.core$eval__4281.invoke(core.clj:2135)
at clojure.main$repl__6358$read_eval_print__6366.invoke(main.clj:183)
at clojure.main$repl__6358.doInvoke(main.clj:200)
at clojure.lang.RestFn.invoke(RestFn.java:422)
at clojure.main$repl_opt__6392.invoke(main.clj:254)
at clojure.main$main__6418.doInvoke(main.clj:347)
at clojure.lang.RestFn.invoke(RestFn.java:398)
at clojure.lang.Var.invoke(Var.java:361)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.NullPointerException: Expecting Symbol + Namespace
at clojure.lang.Namespace.addAlias(Namespace.java:184)
at clojure.core$alias__4566.invoke(core.clj:2892)
at user$eval__11.invoke(NO_SOURCE_FILE:7)
at clojure.lang.Compiler.eval(Compiler.java:5332)
... 17 more
</code></pre>
And the clj:
<pre><code>(defn alias
"Add an alias in the current namespace to another
namespace. Arguments are two symbols: the alias to be used, and
the symbolic name of the target namespace. Use :as in the ns macro in preference
to calling this directly."
[alias namespace-sym]
(.addAlias *ns* alias (find-ns namespace-sym)))
Clearly, the clojure is doing find-ns and the namespace is not known so it passes a null down. Seems like the code in either the clj or java level could say "Hey dummy, you used an unknown namespace" instead of "Expecting Symbol + Namespace". Maybe this would be useful as an additional sentence in the alias doc string too.
Converted from http://www.assembla.com/spaces/clojure/tickets/320