-
Notifications
You must be signed in to change notification settings - Fork 464
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
Avoid exceptions when dumping ctx #624
Conversation
try { | ||
((Loggeable) value).dump(p, indent + " "); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be nice to also print an explanation of what happened, so it is clearer at a first look to the std err, that it was an exception while dumping before having to pay attention to the stack trace.
This could even be a new log event to be sent to the default logger, with the message and the exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not printing to stderr, it goes to the PrintStream, along with the rest of the message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last time I checked ex.printStackTrace, printed to std err.
Prints this throwable and its backtrace to the standard error stream. This method prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err. The first line of output contains the result of the toString() method for this object. Remaining lines represent data previously recorded by the method fillInStackTrace(). The format of this information depends on the implementation, but the following example may be regarded as typical:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups, sorry, I didn't see the pint stream parameter 🤦🏼♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my tests, it will appear like
ACCOUNT: org.hibernate.LazyInitializationException: could not initialize proxy [org.jpos.gl.FinalAccount#1980] - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:176)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:322)
... (more stack trace) ...
and then continue with the rest of the ctx dump as usual, closing every XML tag correctly
(at least for the toString()
case... not sure the Loggeable
one)
When dumping the transaction manager context entries, if an exception was thrown in the
dump()
of aLoggeable
or thetoString()
of the last-resort case for printing an entry value, then the context dump would explode with the exception.This had two problems:
For example
As can be seen, the
toString()
of the value for theACCOUNT
entry (some hibernate proxy in the example, but it's irrelevant to the explanation), threw anException
.The rest of the ctx is not dumped, but worse:
</context>
and</abort>
are not closed.This PR fixes that.