When clojure.contrib.test-is/run-tests is given an invalid argument, it 
throws a NullPointerException:

user=> (use 'clojure.contrib.test-is)
nil
user=> (run-tests 'asdf)
java.lang.RuntimeException: java.lang.NullPointerException 
(NO_SOURCE_FILE:0)

The issue seems harmless in a simple case like this, but in a more 
complex case the error is quite hard to debug for two reasons:
- When the stack trace is longer it's not immediately obvious what 
caused the NullPointerException.
- The error can be caused by a simple typo so it's quite easy to miss 
when reading the code because the code "reads aloud" correctly.

Having something like 'clojure.contrib.test-is.NamespaceException: No 
such namespace "asdf"' would make the source of the error easy to find.

I found this bug by having a namespace called "errorr" (deliberate 
typo), and accidentally spelled it correctly as "error" in the argument 
to run-tests. You might say that I got what I deserved for picking a 
clever Web2.0 name like that (and I would agree :), but keep in mind 
that any other typo would have worked and could have been as hard to find.

As an example, here's the the stack trace that one typo gave me.

Exception in thread "main" java.lang.RuntimeException: 
java.lang.NullPointerException (run-tests.clj:0)
        at clojure.lang.Compiler.eval(Compiler.java:4543)
        at clojure.lang.Compiler.load(Compiler.java:4857)
        at clojure.lang.Compiler.loadFile(Compiler.java:4824)
        at clojure.main$load_script__5833.invoke(main.clj:206)
        at clojure.main$script_opt__5864.invoke(main.clj:258)
        at clojure.main$main__5888.doInvoke(main.clj:333)
        at clojure.lang.RestFn.invoke(RestFn.java:413)
        at clojure.lang.Var.invoke(Var.java:346)
        at clojure.lang.AFn.applyToHelper(AFn.java:173)
        at clojure.lang.Var.applyTo(Var.java:463)
        at clojure.main.main(main.java:39)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at clojure.lang.LazySeq.seq(LazySeq.java:46)
        at clojure.lang.RT.seq(RT.java:436)
        at clojure.core$seq__3133.invoke(core.clj:103)
        at clojure.core$spread__3240.invoke(core.clj:383)
        at clojure.core$spread__3240.invoke(core.clj:384)
        at clojure.core$apply__3243.doInvoke(core.clj:390)
        at clojure.lang.RestFn.invoke(RestFn.java:443)
        at clojure.contrib.test_is$run_tests__4789.doInvoke(test_is.clj:914)
        at clojure.lang.RestFn.invoke(RestFn.java:413)
        at errorr.engine.gfx.tests$run__7.invoke(tests.clj:5)
        at user$eval__10.invoke(run-tests.clj:2)
        at clojure.lang.Compiler.eval(Compiler.java:4532)
        ... 10 more
Caused by: java.lang.NullPointerException
        at 
java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
        at clojure.lang.Namespace.find(Namespace.java:129)
        at clojure.core$find_ns__4309.invoke(core.clj:2347)
        at clojure.core$the_ns__4321.invoke(core.clj:2371)
        at clojure.core$ns_name__4325.invoke(core.clj:2376)
        at clojure.contrib.test_is$fn__4660.invoke(test_is.clj:586)
        at clojure.lang.MultiFn.invoke(MultiFn.java:157)
        at clojure.contrib.test_is$test_ns__4785.invoke(test_is.clj:896)
        at clojure.core$map__3815$fn__3817.invoke(core.clj:1503)
        at clojure.lang.LazySeq.seq(LazySeq.java:41)
        ... 21 more

--
Timo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to