Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception with long seqs #220

Open
msolli opened this issue Apr 28, 2022 · 2 comments
Open

Exception with long seqs #220

msolli opened this issue Apr 28, 2022 · 2 comments

Comments

@msolli
Copy link
Contributor

msolli commented Apr 28, 2022

I ran into an exception while rendering a long-ish sequence of things in a PDF. I can reproduce the exception in a more minimal fashion with this code:

(let [things      (repeat 46 "foo")
      show-things (fn [x] [:paragraph x])]
  (clj-pdf.core/pdf
    [{}
     (map show-things things)]
    "doc.pdf"))

On my machine, this produces:

Execution error (ExceptionConverter) at (REPL:1).
null

The value of *e in the REPL is:

#error{:cause nil, :via [{:type com.lowagie.text.ExceptionConverter, :message nil}], :trace []}

Not much info there. But if I change the number 46 to 45, it works. I converged on these numbers by trial and error.

@yogthos
Copy link
Collaborator

yogthos commented Apr 28, 2022

I can reproduce the issue locally. Unfortunately, there really isn't much to go on from the stack trace, but it appears that it might be a bug in the underlying OpenPDF library.

@msolli
Copy link
Contributor Author

msolli commented May 2, 2022

Thanks, good that you could reproduce locally. It was driving me crazy.

Anyway, I was wondering about the number 46, which seemed overly arbitrary to me. Then I had a look at the PDF for the number 45. The whole page was filled. So my hypothesis now is that the 46th line is causing a new page, and that this somehow break things. I then tried some other numbers, and the number 90 gave me the same NullPointerException, but this time with a stacktrace (I have no idea why).

Observe:

(let [things      (repeat 90 {:foo "foo"})
      show-things (fn [{:keys [foo]}] [:paragraph foo])]
  (clj-pdf.core/pdf
    [{}
     (map show-things things)]
    "doc.pdf"))

Output:

Execution error (NullPointerException) at clj-pdf.core/write-header-footer-content-row (core.clj:167).
null
*e
=>
#error{:cause nil,
       :via [{:type com.lowagie.text.DocumentException,
              :message "java.lang.NullPointerException",
              :at [com.lowagie.text.pdf.PdfDocument add "PdfDocument.java" 776]}
             {:type java.lang.NullPointerException, :message nil, :at [clojure.lang.RT floatCast "RT.java" 1317]}],
       :trace [[clojure.lang.RT floatCast "RT.java" 1317]
               [clj_pdf.core$write_header_footer_content_row invokeStatic "core.clj" 167]
               [clj_pdf.core$write_header_footer_content_row invoke "core.clj" 166]
               [clj_pdf.core$table_footer_header_event$fn__135242 invoke "core.clj" 185]
               [clj_pdf.core.proxy$com.lowagie.text.pdf.PdfPageEventHelper$ff19274a onEndPage nil -1]
               [com.lowagie.text.pdf.PdfDocument newPage "PdfDocument.java" 903]
               [com.lowagie.text.pdf.PdfDocument carriageReturn "PdfDocument.java" 1282]
               [com.lowagie.text.pdf.PdfDocument add "PdfDocument.java" 558]
               [com.lowagie.text.Document add "Document.java" 302]
               [clj_pdf.core$append_to_doc invokeStatic "core.clj" 111]
               [clj_pdf.core$append_to_doc invoke "core.clj" 107]
               [clj_pdf.core$add_item invokeStatic "core.clj" 484]
               [clj_pdf.core$add_item invoke "core.clj" 481]
               [clj_pdf.core$write_doc invokeStatic "core.clj" 515]
               [clj_pdf.core$write_doc invoke "core.clj" 503]
               [clj_pdf.core$pdf invokeStatic "core.clj" 572]
               [clj_pdf.core$pdf invoke "core.clj" 560]
               [vilect.pdf.candidates$eval150334 invokeStatic "candidates.clj" 3]
               [vilect.pdf.candidates$eval150334 invoke "candidates.clj" 163]
               [clojure.lang.Compiler eval "Compiler.java" 7194]
               [clojure.lang.Compiler eval "Compiler.java" 7149]
               [clojure.core$eval invokeStatic "core.clj" 3215]
               [clojure.core$eval invoke "core.clj" 3211]
               [nrepl.middleware.interruptible_eval$evaluate$fn__33082$fn__33083 invoke "interruptible_eval.clj" 87]
               [clojure.lang.AFn applyToHelper "AFn.java" 152]
               [clojure.lang.AFn applyTo "AFn.java" 144]
               [clojure.core$apply invokeStatic "core.clj" 667]
               [clojure.core$with_bindings_STAR_ invokeStatic "core.clj" 1990]
               [clojure.core$with_bindings_STAR_ doInvoke "core.clj" 1990]
               [clojure.lang.RestFn invoke "RestFn.java" 425]
               [nrepl.middleware.interruptible_eval$evaluate$fn__33082 invoke "interruptible_eval.clj" 87]
               [clojure.main$repl$read_eval_print__9206$fn__9209 invoke "main.clj" 437]
               [clojure.main$repl$read_eval_print__9206 invoke "main.clj" 437]
               [clojure.main$repl$fn__9215 invoke "main.clj" 458]
               [clojure.main$repl invokeStatic "main.clj" 458]
               [clojure.main$repl doInvoke "main.clj" 368]
               [clojure.lang.RestFn invoke "RestFn.java" 1523]
               [nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 84]
               [nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 56]
               [nrepl.middleware.interruptible_eval$interruptible_eval$fn__33115$fn__33119
                invoke
                "interruptible_eval.clj"
                152]
               [clojure.lang.AFn run "AFn.java" 22]
               [nrepl.middleware.session$session_exec$main_loop__33185$fn__33189 invoke "session.clj" 218]
               [nrepl.middleware.session$session_exec$main_loop__33185 invoke "session.clj" 217]
               [clojure.lang.AFn run "AFn.java" 22]
               [java.lang.Thread run "Thread.java" 829]]}

Line 167 of clj-pdf.core is the body of this function:

(defn write-header-footer-content-row [{:keys [table x y]} ^PdfWriter writer]
  (.writeSelectedRows ^PdfPTable table (int 0) (int -1) (float x) (float y) (.getDirectContent writer)))

Seems one or more of the locals here are nil. I put a breakpoint on the line that invokes this function and got this:
Skjermbilde 2022-05-02 kl  12 56 18

So, it seems header-content is nil. This value is ultimately passed from the table-header local in setup-doc.

Does this give some hint as to what might be wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants