<< Back to previous view

[CLJ-1102] Better handling of exceptions with empty stack traces Created: 04/Nov/12  Updated: 25/Oct/13  Resolved: 25/Oct/13

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.5
Fix Version/s: Release 1.6

Type: Defect Priority: Minor
Reporter: Andy Fingerhut Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: errormsgs

Attachments: File clj-1102-improve-empty-stack-trace-handling-v2.diff     Text File clj-1102-improve-empty-stack-trace-handling-v2.txt    
Patch: Code and Test
Approval: Ok


REPL session demonstrating clojure.stacktrace/print-stack-trace and clojure.test/file-and-line throwing exceptions when given Throwable with an empty stack trace:

user=> (require '[clojure.stacktrace :as s])
user=> (def empty-stack (into-array (Class/forName "java.lang.StackTraceElement") []))
user=> (def t (doto (Throwable.) (.setStackTrace empty-stack)))
user=> (def msg (with-out-str (s/print-stack-trace t)))

NullPointerException   clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:296)
user=> msg
#<Unbound Unbound: #'user/msg>
user=> (require 'clojure.test)
user=> (def m1 (#'clojure.test/file-and-line t 0))

ArrayIndexOutOfBoundsException   java.lang.reflect.Array.get (Array.java:-2)
user=> m1
#<Unbound Unbound: #'user/m1>

I have seen this cause confusing output when exceptions with empty stack traces are thrown while running tests on a project. According to the Java docs for Throwable, it is permissible for getStackTrace to do this:



I found all places in the Clojure code that call getStackTrace. Among them, two did not handle an empty stack trace correctly.

Output of tests above with this patch applied:


user=> (def msg (with-out-str (s/print-stack-trace t)))
user=> (print msg)
java.lang.Exception: null
 at [empty stack trace]


user=> (def m1 (#'clojure.test/file-and-line t 0))
user=> m1
{:line nil, :file nil}

Patch: clj-1102-improve-empty-stack-trace-handling-v2.diff

Screened by: Alex Miller

Comment by Andy Fingerhut [ 04/Nov/12 5:07 PM ]

clj-1102-improve-empty-stack-trace-handling-v1.txt dated Nov 4 2012 improves the handling of .getStackTrace returning a length 0 array in two places. I checked all other places .getStackTrace was called and they seem to already handle this case gracefully.

Comment by Timothy Baldridge [ 30/Nov/12 2:57 PM ]


Generated at Thu Jan 18 13:53:20 CST 2018 using JIRA 4.4#649-r158309.