title: Where is my Null Pointer Exception - Clojure edition
body: <p>I am getting the following stacktrace when running the command: <code>lein run "this is the other different thing" "this,different,other"</code></p>
  
  <p>Stacktrace</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException, compiling:(/private/var/folders/y8/6lt_81xn47d4n2k641z52rg00000gn/T/form-init8328218573408236617.clj:1:125)
      at clojure.lang.Compiler.load(Compiler.java:7391)
      at clojure.lang.Compiler.loadFile(Compiler.java:7317)
      at clojure.main$load_script.invokeStatic(main.clj:275)
      at clojure.main$init_opt.invokeStatic(main.clj:277)
      at clojure.main$init_opt.invoke(main.clj:277)
      at clojure.main$initialize.invokeStatic(main.clj:308)
      at clojure.main$null_opt.invokeStatic(main.clj:342)
      at clojure.main$null_opt.invoke(main.clj:339)
      at clojure.main$main.invokeStatic(main.clj:421)
      at clojure.main$main.doInvoke(main.clj:384)
      at clojure.lang.RestFn.invoke(RestFn.java:421)
      at clojure.lang.Var.invoke(Var.java:383)
      at clojure.lang.AFn.applyToHelper(AFn.java:156)
      at clojure.lang.Var.applyTo(Var.java:700)
      at clojure.main.main(main.java:37)
  Caused by: java.lang.NullPointerException
      at clojure.string$replace.invokeStatic(string.clj:101)
      at clojure.string$replace.invoke(string.clj:75)
      at redact.core$redact_doc.invokeStatic(core.clj:12)
      at redact.core$redact_doc.invoke(core.clj:7)
      at redact.core$_main.invokeStatic(core.clj:54)
      at redact.core$_main.doInvoke(core.clj:50)
      at clojure.lang.RestFn.invoke(RestFn.java:421)
      at clojure.lang.Var.invoke(Var.java:383)
      at user$eval5.invokeStatic(form-init8328218573408236617.clj:1)
      at user$eval5.invoke(form-init8328218573408236617.clj:1)
      at clojure.lang.Compiler.eval(Compiler.java:6927)
      at clojure.lang.Compiler.eval(Compiler.java:6917)
      at clojure.lang.Compiler.load(Compiler.java:7379)
      ... 14 more
  </code></pre>
  
  <p>And here is my code:</p>
  
  <pre><code>(ns redact.core
    (:gen-class)
    (:require [clojure.java.io :as io]
              [clojure.string :as str]
  ))
  
  (defn redact-doc
    ;; Reads the file line by line and redacts all the matched words
    ([target stoplist]
     (if (empty? stoplist)
       (str/trim target)
       (redact-doc (str/replace target (re-pattern (str "\\s(" (first stoplist) ")(\\s|$)")) " REDACTED ") (rest stoplist))))
    )
  
  (defn get-target-text
    ;; Takes a vector of args and returns a String of a text file or and sentances
    ([args] (get-target-text args ""))
    ([args result]
     (if (empty? args)
       result
       (get-target-text (rest args) (if (boolean (re-find #"(.+\.[^csv\s])" (first args)))
                                      (str result (slurp (first args)))
                                      (if (not (boolean (re-find #"(.+\.csv|.+,.+)" (first args))))
                                        (if (boolean (re-find #"\s" (str/trim (first args))))
                                          (str result (first args) " ")))))))
   )
  
  (defn read-csv
    ;; Takes in a filename and returns a vector of the csv values
    [file-name]
    (str/split (with-open [rdr (io/reader file-name)]
       (doall (reduce str (line-seq rdr)))) #","))
  
  (defn gen-stoplist
    ;; Generates the stoplist for words to be redacted
    ([args] (gen-stoplist args []))
    ([args stoplist]
     (if (empty? args)
       stoplist
       (gen-stoplist (rest args) (if (boolean (re-find #"(.+\.csv)" (first args)))
                                   (into [] (concat stoplist (read-csv (first args))))
                                   (if (boolean (re-find #"(.+\..[^csv\s])" (first args)))
                                     stoplist
                                     (if (boolean (re-find #"(.*,.*)" (first args))) 
                                       (into [] (concat stoplist (str/split (first args) #",")))
                                       (if (boolean (re-find #"(\s)" (str/trim (first args))))
                                         stoplist
                                         (into [] (concat stoplist [(first args)] ))))))))))
  
  (defn -main
    ([&amp; args]
     (def stoplist (gen-stoplist args))
     (def target-text (get-target-text args))
     (println (redact-doc target-text stoplist)))
  )
  </code></pre>
  
  <p>I have been staring at this trying to figure out what is causing the issue. I have tested all of the methods independently on the REPL and they all seem to work but the (-main) method is throwing a null pointer exception on the str/replace call....just not sure why. Any help you can give is much appreciated. Thanks!</p>