1

I am using resolve to call a function given they name (String), like

(call "+" 10 10 10) ;; 30

The call function:

(defn call [this & that]
  (apply (resolve (symbol this)) that))

Everything works fine on REPL. But when I start the project as a server using httpkit http server, I receive a NPE.

java.lang.NullPointerException
    at clojure.core$apply.invoke(core.clj:626)
    at tapahtuma.http_resources$call.doInvoke(http_resources.clj:41)
    at clojure.lang.RestFn.invoke(RestFn.java:423)
    at tapahtuma.http_resources$forwarder.invoke(http_resources.clj:61)
    at tapahtuma.http_resources$create_event.invoke(http_resources.clj:69)
    at compojure.response$eval1563$fn__1564.invoke(response.clj:26)
    at compojure.response$eval1524$fn__1525$G__1515__1532.invoke(response.clj:10)
    at compojure.core$make_route$fn__1699.invoke(core.clj:93)
    at compojure.core$if_route$fn__1683.invoke(core.clj:39)
    at compojure.core$if_method$fn__1676.invoke(core.clj:24)
    at compojure.core$routing$fn__1705.invoke(core.clj:106)
    at clojure.core$some.invoke(core.clj:2528)
    at compojure.core$routing.doInvoke(core.clj:106)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invoke(core.clj:628)
    at compojure.core$routes$fn__1709.invoke(core.clj:111)
    at tapahtuma.http_resources$wrap_content_type$fn__7192.invoke(http_resources.clj:22)
    at ring.middleware.cors$wrap_cors$fn__1800.invoke(cors.clj:47)
    at org.httpkit.server.HttpHandler.run(RingHandler.java:33)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

At line 41 of http_resources I have the call function.

I don't figured out what are happen here. Thanks for any help here. I created a project to help reproduce the problem

4
  • How much code would you need to add a proper reproducer? If that could be done tersely, it would certainly help. Commented May 12, 2015 at 16:00
  • @CharlesDuffy I will prepare a project to reproduce the issue. I will post here as soon is possible. Thanks Commented May 12, 2015 at 16:18
  • @CharlesDuffy mybe this help: github.com/edipofederle/resolve-clj Commented May 12, 2015 at 16:51
  • Yes -- exceedingly helpful, thank you. Commented May 12, 2015 at 17:05

1 Answer 1

2

The following modification to your reproducer -- fully qualifying the namespace -- works properly:

(defn call [this & that]
  (let [this-sym (symbol this)
        this-resolved (ns-resolve 'resolver-clj.core this-sym)]
     (.println System/out (str "current-ns: " *ns*))
     (.println System/out (str "this-sym: " this-sym))
     (.println System/out (str "this-resolved: " this-resolved))
     (apply this-resolved that)))

The reason is obvious when you look at the value of *ns* in the reproduction environment, which is clojure.core.

Sign up to request clarification or add additional context in comments.

1 Comment

great. Thanks. I thought about ns but not investigate properly. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.