NullPointerException in clojure.stacktrace?

14 views
Skip to first unread message

Stuart Sierra

unread,
Oct 1, 2010, 11:03:44 AM10/1/10
to cloju...@googlegroups.com
This is a very rare edge case. So rare, in fact, that I can't
reproduce it by hand. But I swear I've seen it happen, especially in
web apps.

What happens is this:

1. App throws an exception.

2. Some wrapper catches the exception an calls
clojure.stacktrace/print-cause-trace.

3. clojure.stacktrace/print-trace-element tries to match
StackTraceElement.getClass against a regex.

4. StackTraceElement.getClass returns null, so a NullPointerException
gets thrown, totally obscuring the original exception.

Now, step 4 is supposedly impossible, according to the Javadocs for
StackTraceElement. But maybe in certain strange cases it can happen.

A simple patch (attached) will fix this.

-S

fix-stacktrace1.diff

Alex Miller

unread,
Oct 1, 2010, 11:41:28 AM10/1/10
to cloju...@googlegroups.com
There was an interesting code review that went through the jdk core-libs list recently that resulted in finding what looked like some incorrectly synchronized code in this area.  The bug was fixed in one of the very latest JDK 7 builds.  Perhaps it is related?

Bug:

Start of thread:




From: Stuart Sierra <the.stua...@gmail.com>
To: cloju...@googlegroups.com
Sent: Fri, October 1, 2010 10:03:44 AM
Subject: NullPointerException in clojure.stacktrace?
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.

Alex Miller

unread,
Oct 1, 2010, 11:45:57 AM10/1/10
to cloju...@googlegroups.com
In particular methods like getCause() were not properly synchronized, which means you could be seeing in-flight data below that (like the class).  See the added synchronization in the final changeset:


This was added in August for JDK7 build 109.


From: Alex Miller <alexd...@yahoo.com>
To: cloju...@googlegroups.com
Sent: Fri, October 1, 2010 10:41:28 AM
Subject: Re: NullPointerException in clojure.stacktrace?
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.

Stuart Sierra

unread,
Oct 1, 2010, 2:00:08 PM10/1/10
to Clojure Dev
On Oct 1, 11:41 am, Alex Miller <alexdmil...@yahoo.com> wrote:
> There was an interesting code review that went through the jdk core-libs list
> recently that resulted in finding what looked like some incorrectly synchronized
> code in this area.  The bug was fixed in one of the very latest JDK 7 builds.
>  Perhaps it is related?

Could well be related. Thanks, Alex.

I'll create a ticket for this.
-S

Stuart Sierra

unread,
Oct 1, 2010, 2:14:31 PM10/1/10
to Clojure Dev
Created ticket #449 with patch.

http://www.assembla.com/spaces/clojure/tickets/449
-S
Reply all
Reply to author
Forward
0 new messages