Null Pointer Exception

Just a function that’ll detele something called a status by it’s ID.
FUNCTION:

(defn del-st!
  [{ds :ds channel :channel} org-id id]
  (println "Deleting Status")
  (try
    (j/with-transaction [transaction ds]
      (let [{result ::j/update-count} (j/execute-one!
                                       transaction
                                       (sql/sql
                                        (sql/delete db :status
                                          (sql/where `(and
                                                       (= :id ~id)
                                                       (= :org-id ~org-id))))))]
        (println "result" result)
        (when (> result 0)
          (chan/publish-event! channel
                               {::chan/event :delete-status
                                ::chan/data {:id id
                                             :org-id org-id}}))))
    (catch SQLException _
      (throw (IllegalArgumentException. "The status you are trying to remove is associated with process(es)")))))

It is called by
INTERCEPTOR:

(def st-del
  {:name :st-del
   :enter
   (fn [context]
     (println "GOING IN" context)
     (let [system (get-in context [:request :system])
           {org-id :org-id} (get-in context [:request])
           {status-id :id} (get-in context [:request :path-params])]
       (println "orgid statusid" org-id status-id)
       (w/del-st! system
                  org-id
                  (read-string status-id))
       (assoc context
              :response {:status 204})))})

This is the route for handling it
ROUTE: ["/workflow/status/:id" :delete [session-check `st-del]]

Now the req is being sent: http://localhost:3593/workflow/status/53 where 53 is the id…
ERROR:

ERROR [io.pedestal.http.impl.servlet-interceptor:128] - {:msg "error-stylobate triggered"
And then directly this:
java.lang.NullPointerException: Cannot invoke "java.lang.Character.charValue()" because "x" is null
    clojure.lang.ExceptionInfo: java.lang.NullPointerException in Interceptor :io.pedestal.http.impl.servlet-interceptor/ring-response - Cannot invoke "java.lang.Character.charValue()" because "x" is null
    exception-type: :java.lang.NullPointerException
      execution-id: 50
       interceptor: :io.pedestal.http.impl.servlet-interceptor/ring-response
             stage: :leave

What is the print out of the id and org-id variables from these calls?

Nothing it’s not even going inside that just that error nothing else

So what could be going wrong here @magnus0re ?

no clue, the problem seems to be somewhere else

Can you please take a look at this @generateme… thank you.

My guess would be this function throws, because status-id is not a string.

Can you log the stack trace? It would tell you exactly where the error is thrown from.

But read-string reads an int to string?

This is the error nothing else… @didibus

INFO [io.pedestal.http:116] - {:msg "DELETE /workflow/status/53", :line 80}
INFO [io.pedestal.http.cors:116] - {:msg "cors request processing", :origin "", :allowed true, :line 84}
INFO [io.pedestal.http.cors:116] - {:msg "cors response processing", :cors-headers {"Access-Control-Allow-Origin" "", "Access-Control-Allow-Credentials" "true", "Access-Control-Expose-Headers" "Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, X-Xss-Protection, X-Download-Options, X-Permitted-Cross-Domain-Policies, Content-Security-Policy"}, :line 111}
ERROR [io.pedestal.http.impl.servlet-interceptor:128] - {:msg "error-stylobate triggered", :context {:response {:headers {"X-Frame-Options" "DENY", "Access-Control-Allow-Origin" "", "X-XSS-Protection" "1; mode=block", "X-Download-Options" "noopen", "Strict-Transport-Security" "max-age=31536000; includeSubdomains", "X-Permitted-Cross-Domain-Policies" "none", "Access-Control-Allow-Credentials" "true", "Access-Control-Expose-Headers" "Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, X-Xss-Protection, X-Download-Options, X-Permitted-Cross-Domain-Policies, Content-Security-Policy", "X-Content-Type-Options" "nosniff", "Content-Security-Policy" "default-src 'none'; frame-ancestors 'none'"}}, :cors-headers {"Access-Control-Allow-Origin" "", "Access-Control-Allow-Credentials" "true"}, :io.pedestal.interceptor.chain/stack (#Interceptor{:name :io.pedestal.http.impl.servlet-interceptor/terminator-injector}), :request {:system {:firebase {:app #object[com.google.firebase.FirebaseApp 0x365324b1 "FirebaseApp{name=[DEFAULT]}"], :api-key nil}, :email {:web-url "http://app.myapp.com", :lite-url "http://lite.myapp.com", :sender nil, :db {:datasource #object[com.zaxxer.hikari.HikariDataSource 0x3f71b434 "HikariDataSource (HikariPool-1)"]}, :inbound-domain nil}, :redis {:pool {}, :spec {:host "127.0.0.1", :port 6379}}, :myapp.aws/dynamodb #object[cognitect.aws.client.Client 0x37d556f0 "cognitect.aws.client.Client@37d556f0"], :db {:datasource #object[com.zaxxer.hikari.HikariDataSource 0x3f71b434 "HikariDataSource (HikariPool-1)"]}, :myapp/redis {:pool {}, :spec {:host "127.0.0.1", :port 6379}}, :myapp/db {:datasource #object[com.zaxxer.hikari.HikariDataSource 0x3f71b434 "HikariDataSource (HikariPool-1)"]}, :cloud-storage #object[com.google.firebase.FirebaseApp 0x365324b1 "FirebaseApp{name=[DEFAULT]}"], :channel #object[clojure.core.async.impl.channels.ManyToManyChannel 0x7794f670 "clojure.core.async.impl.channels.ManyToManyChannel@7794f670"], :pdf {:pdf-key "pdf-api-key", :pdf-base-url "pdf-base-url", :pdf-workspace "pdf-workspace", :pdf-secret "pdf-api-secret"}, :firestore #object[com.google.cloud.firestore.FirestoreImpl 0x4d589ec5 "com.google.cloud.firestore.FirestoreImpl@4d589ec5"], :lite-url "http://lite.myapp.com", :ds #object[com.zaxxer.hikari.HikariDataSource 0x3f71b434 "HikariDataSource (HikariPool-1)"], :port "3593", :myapp/ds #object[com.zaxxer.hikari.HikariDataSource 0x3f71b434 "HikariDataSource (HikariPool-1)"], :rate-limiter #object[clj_rate_limiter.core.MemoryRateLimiterFactory$reify__41408 0x62815d73 "clj_rate_limiter.core.MemoryRateLimiterFactory$reify__41408@62815d73"], :analytics #object[com.segment.analytics.Analytics 0x7f7ee505 "com.segment.analytics.Analytics@7f7ee505"], :host "0.0.0.0", :buckets {:storage "myapp-kishore.appspot.com", :email "myapp-kishore.appspot.com"}, :myapp/reporting-database :}, :protocol "HTTP/1.1", :async-supported? true, :remote-addr "127.0.0.1", :servlet-response #object[org.eclipse.jetty.server.Response 0x605b9156 "HTTP/1.1 200 \nDate: Sun, 13 Jun 2021 01:48:35 GMT\r\n\r\n"], :servlet #object[io.pedestal.http.servlet.FnServlet 0x67243afb "io.pedestal.http.servlet.FnServlet@67243afb"], :headers {"origin" "", "x-myapp-token" "eyJhbGciOiJSUzI1NiIsImtpZCI6ImRjNGQwMGJjM2NiZWE4YjU0NTMzMWQxZjFjOTZmZDRlNjdjNTFlODkiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiS2lzaG9yZSBLYXJuYW0iLCJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vdW5pZml6ZS1raXNob3JlIiwiYXVkIjoidW5pZml6ZS1raXNob3JlIiwiYXV0aF90aW1lIjoxNjEyNDIwODI3LCJ1c2VyX2lkIjoiTDBRR3A4SjNQMGZGTnE3ZUdlUjdUbDYxVXVMMiIsInN1YiI6IkwwUUdwOEozUDBmRk5xN2VHZVI3VGw2MVV1TDIiLCJpYXQiOjE2MjM1NDg4NzEsImV4cCI6MTYyMzU1MjQ3MSwiZW1haWwiOiJraXNob3JlLmthcm5hbUB1bmlmaXplLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7ImVtYWlsIjpbImtpc2hvcmUua2FybmFtQHVuaWZpemUuY29tIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.gcA87c5u59e9ZgKlEAW-yxcRei8qKBVNkkYG0OlAe35cIgQAevASc7csSnV3tK1YhSweFbcSsO4XCfshQ8qWUq1CvtI6NuOjmRfBbZobIyXQrToPo-0H_ZtyuyqpvvOCPSAJCYe5DJ4awXszKtN-sMa3f19Zb-vlgt3r8OYQApiudsO2-i_cGkWYiUSqF1UsiBckFoJetE5oTt1Bhuxj3twPmBP1XmW1v4f9C6BgS1S9qgRmxqcS3NBjqL_WlXbpyQT1nDxuS4dPye-_gfwgjJ-p4TFPJs36eXK_fAwUxSo63ibKrHhVnhIPR4WMmkv8jIi3MT6XdObLjhx0YeZH1w", "host" "localhost:3593", "user-agent" "PostmanRuntime/7.28.0", "x-myapp-org" "1", "connection" "keep-alive", "accept" "*/*", "accept-encoding" "gzip, deflate, br", "postman-token" "f31f9120-3ebe-4e2b-b51c-1fc74ed17934"}, :server-port 3593, :servlet-request #object[org.eclipse.jetty.server.Request 0xd1f5f58 "Request(DELETE //localhost:3593/workflow/status/53)@d1f5f58"], :path-info "/workflow/status/53", :uri "/workflow/status/53", :server-name "localhost", :query-string nil, :body #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x53bdb03e "HttpInputOverHTTP@53bdb03e[c=0,q=0,[0]=null,s=STREAM]"], :scheme :http, :request-method :delete, :context-path ""}, :enter-async [#function[io.pedestal.http.impl.servlet-interceptor/start-servlet-async]], :io.pedestal.interceptor.chain/terminators (#function[io.pedestal.http.impl.servlet-interceptor/terminator-inject/fn--61001]), :servlet-response #object[org.eclipse.jetty.server.Response 0x605b9156 "HTTP/1.1 200 \nDate: Sun, 13 Jun 2021 01:48:35 GMT\r\n\r\n"], :route nil, :servlet #object[io.pedestal.http.servlet.FnServlet 0x67243afb "io.pedestal.http.servlet.FnServlet@67243afb"], :servlet-request #object[org.eclipse.jetty.server.Request 0xd1f5f58 "Request(DELETE //localhost:3593/workflow/status/53)@d1f5f58"], :kebab-params nil, :result nil, :io.pedestal.interceptor.chain/execution-id 44, :servlet-config #object[org.eclipse.jetty.servlet.ServletHolder$Config 0x59e2fac0 "org.eclipse.jetty.servlet.ServletHolder$Config@59e2fac0"], :async? #function[io.pedestal.http.impl.servlet-interceptor/servlet-async?]}, :line 242}
                                                   java.lang.Thread.run                  Thread.java:  832
              org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run        QueuedThreadPool.java:  804
                  org.eclipse.jetty.util.thread.QueuedThreadPool.runJob        QueuedThreadPool.java:  698
org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run  ReservedThreadExecutor.java:  366
              org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run          EatWhatYouKill.java:  126
       org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce          EatWhatYouKill.java:  168
        org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce          EatWhatYouKill.java:  310
          org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask          EatWhatYouKill.java:  333
                             org.eclipse.jetty.io.ChannelEndPoint$2.run         ChannelEndPoint.java:  117
                             org.eclipse.jetty.io.FillInterest.fillable            FillInterest.java:  103
         org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded      AbstractConnection.java:  305
                     org.eclipse.jetty.server.HttpConnection.onFillable          HttpConnection.java:  267
                            org.eclipse.jetty.server.HttpChannel.handle             HttpChannel.java:  370
                                 org.eclipse.jetty.server.Server.handle                  Server.java:  505
                 org.eclipse.jetty.server.handler.HandlerWrapper.handle          HandlerWrapper.java:  132
                  org.eclipse.jetty.server.handler.ScopedHandler.handle           ScopedHandler.java:  144
                org.eclipse.jetty.server.handler.ContextHandler.doScope          ContextHandler.java: 1247
               org.eclipse.jetty.server.handler.ScopedHandler.nextScope           ScopedHandler.java:  201
                       org.eclipse.jetty.servlet.ServletHandler.doScope          ServletHandler.java:  480
               org.eclipse.jetty.server.handler.ScopedHandler.nextScope           ScopedHandler.java:  203
               org.eclipse.jetty.server.handler.ContextHandler.doHandle          ContextHandler.java: 1345
              org.eclipse.jetty.server.handler.ScopedHandler.nextHandle           ScopedHandler.java:  255
                      org.eclipse.jetty.servlet.ServletHandler.doHandle          ServletHandler.java:  542
                         org.eclipse.jetty.servlet.ServletHolder.handle           ServletHolder.java:  873
                             io.pedestal.http.servlet.FnServlet/service                  servlet.clj:   28
    io.pedestal.http.impl.servlet-interceptor/interceptor-service-fn/fn      servlet_interceptor.clj:  351
                                  io.pedestal.interceptor.chain/execute                    chain.clj:  389
                                  io.pedestal.interceptor.chain/execute                    chain.clj:  379
                                io.pedestal.interceptor.chain/leave-all                    chain.clj:  266
                                                                    ...                                   
                                            clojure.core/with-bindings*                     core.clj: 1973 (repeats 2 times)
                                                     clojure.core/apply                     core.clj:  665
                                                                    ...                                   
                             io.pedestal.interceptor.chain/leave-all/fn                    chain.clj:  268
                   io.pedestal.interceptor.chain/leave-all-with-binding                    chain.clj:  254
                                    io.pedestal.interceptor.chain/try-f                    chain.clj:   54
          io.pedestal.http.impl.servlet-interceptor/leave-ring-response      servlet_interceptor.clj:  229
                io.pedestal.http.impl.servlet-interceptor/send-response      servlet_interceptor.clj:  165
                 io.pedestal.http.impl.servlet-interceptor/set-response      servlet_interceptor.clj:  157
                                                                    ...                                   
java.lang.NullPointerException: Cannot invoke "java.lang.Character.charValue()" because "x" is null
    clojure.lang.ExceptionInfo: java.lang.NullPointerException in Interceptor :io.pedestal.http.impl.servlet-interceptor/ring-response - Cannot invoke "java.lang.Character.charValue()" because "x" is null
    exception-type: :java.lang.NullPointerException
      execution-id: 44
       interceptor: :io.pedestal.http.impl.servlet-interceptor/ring-response
             stage: :leave

It does look like the interceptor function running on :leave is throwing that exception.

I’m guessing you’ve configured this function to run?

Do you have an interceptor setup to run on :leave?

Though I’m not familiar with pedestal. But you probably want to have your own try/catch, because it looks like it doesn’t throw the error, but captures it and then logs it as a return response. That means I’m not sure if the error happened on leave or if leave is the stage where it reports the error that happened before.

No, read-string reads a string and possibly returns an int if the string encodes an int using Clojure/EDN syntax rules.

If you want to turn an int to a string use pr-str

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.