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

+2 votes
in Errors by

Using lein run. There are no references to my *.clj file anywhere, so I don't know where this java.lang.NullPointerException is coming from??

Exception in thread "main" Syntax error compiling at (/tmp/form-init542794133375754487.clj:1:72).
    at clojure.lang.Compiler.load(Compiler.java:7647)
    at clojure.lang.Compiler.loadFile(Compiler.java:7573)
    at clojure.main$load_script.invokeStatic(main.clj:452)
    at clojure.main$init_opt.invokeStatic(main.clj:454)
    at clojure.main$init_opt.invoke(main.clj:454)
    at clojure.main$initialize.invokeStatic(main.clj:485)
    at clojure.main$null_opt.invokeStatic(main.clj:519)
    at clojure.main$null_opt.invoke(main.clj:516)
    at clojure.main$main.invokeStatic(main.clj:598)
    at clojure.main$main.doInvoke(main.clj:561)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.lang.Var.applyTo(Var.java:705)
    at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
    at xinova.model$reload_dbs.invokeStatic(model.clj:78)
    at xinova.model$reload_dbs.invoke(model.clj:78)
    at xinova.core$_main.invokeStatic(core.clj:18)
    at xinova.core$_main.doInvoke(core.clj:14)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.lang.Var.invoke(Var.java:384)
    at user$eval140.invokeStatic(form-init542794133375754487.clj:1)
    at user$eval140.invoke(form-init542794133375754487.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:7176)
    at clojure.lang.Compiler.eval(Compiler.java:7166)
    at clojure.lang.Compiler.load(Compiler.java:7635)
    ... 12 more

1 Answer

+5 votes
selected by
Best answer

In this particular case, Leiningen is invoking clojure.main as a process and it's the subprocess JVM that is printing the (uncaught) error.

You see two exceptions here - the thrown exception, then a nested cause exception. Java's exception printer will print the "... 12 more" for nested cause stacks when they are the same as the stack already printed in the exception higher in the chain. That is, the 12 more here are exactly the same stack trace lines already printed for the first exception. So, there actually is no more info to be had here - you already have it all.

The key line here is the top line of the bottom-most (root) exception:

at xinova.model$reload_dbs.invokeStatic(model.clj:78)

I don't know what the error is, but I'd guess it's likely there is a Java interop call being made on a nil reference. This is happening while loading the file.

In Clojure 1.10.1, we have modified how uncaught exceptions going through clojure.main are reported. If you switch to that, you'll actually see just the exception message and a longer report that gets dumped to a temp file.

As an aside, The top line message you see here is "Exception in thread "main" Syntax error compiling" - that's actually misleading due to a subtle bug in the exception handling overhaul done in Clojure 1.10. I prepped a ticket and a patch for that earlier this week to fix it in Clojure 1.11 (see CLJ-2529). Basically errors happening in load are mistakenly being reported as compiler exceptions. Doesn't change things too much, but this is an example.