History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2673
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: David Koontz
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

Java exceptions do not return the wrapped exception when getStackTrace is called

Created: 17/Jun/08 06:02 PM   Updated: 10/Sep/08 06:44 PM
Component/s: Java Integration
Affects Version/s: JRuby 1.2
Fix Version/s: JRuby 1.1.4

Time Tracking:
Not Specified

File Attachments: 1. File java_exception_bug.rb (0.5 kb)

Environment: OSX 10.5, Jruby trunk

Testcase included: yes


 Description  « Hide
I have only validated this behavior when using Thread.setDefaultUncaughtExceptionHandler (the test case is attached). A workaround for this is to call .cause on the exception object.

So instead of exception.stack_trace you would do exception.cause.stack_trace.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
David Koontz - 17/Jun/08 06:29 PM
I tried applying the .cause workaround in my actual project and it failed. exception.cause returned nil for the exceptions I was getting. I did manage a workaround since all I wanted was to get a string version of the stack trace to send to my logger (what would have been exception.stack_trace.join("\n")).

I ended up with

output_stream = java.io.ByteArrayOutputStream.new
exception.printStackTrace(java.io.PrintStream.new(output_stream))
LOGGER.fatal(output_stream.to_string)

If I needed the actual stack trace array I would have been SOL.


Charles Oliver Nutter - 25/Aug/08 07:35 PM
Fixed in r7534 by having RaiseException use the original Java exception's stack trace. Essentially I just added an instanceof check to RaiseException, so that when it's wrapping a NativeException it does the "more right" thing. Still kinda gross over all since there's multiple levels of wrapping, but removing any of those wrapping layers would be a breaking change we can't really do in 1.1.x.