-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix stack locator calc location on JDK 9 #109
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
Fix stack locator calc location on JDK 9 #109
Conversation
|
This is for: https://issues.apache.org/jira/browse/LOG4J2-2028 |
|
Finding the frame prior to the first frame that matches the class name of the logger is likely to return a frame that still points at the logger class because multiple methods in the logger may be called. |
|
@rgoers Thanks for the feedback, that makes sense! I will do this:
|
|
@jasontedor Thanks for contributing to Log4j - we appreciate all the help we can get! |
|
You're welcome @rgoers, it is my pleasure. I pushed a commit as we discussed. |
This commit fixes a bug in StackLocator#calcLocation on JDK 9. The particular issue here is that on JDK 9, all stack trace locations report as line 71 of StackLocatorUtil. This is due to a bug in the JDK 9 implementation of StackLocator. The bug is that instead of dropping the top frames of the stack until the first frame that matches the fully-qualified class name of the logger, the implementation would drop all frames from the top that match the fully-qualified class name of the logger. Of course, at this point in the stack trace, there would be none. The fix is to reverse the condition, that we drop all frames until we reach a frame matching the fully-qualified class name of the logger, and then drop all frames matching the fully-qualified class name of the logger. This commit also adds a test that was broken before this change and now passes.
2d9d81b to
02eee31
Compare
Do you happen to have a bug report link? Thank you :) |
rgoers
left a comment
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.
Basically I forgot the ! when walking the elements back to the logger.
|
Thanks @rgoers. |
|
I just tried running one of my webapps on tomcat under Java 9. Although I didn't have much success due to Spring (that is a different story) I do see the location information correctly. |
|
I can confirm that as well, both the unit tests we have that rely on this are passing now, and the application is logging the correct location when |
This commit fixes a bug in StackLocator#calcLocation on JDK 9. The particular issue here is that on JDK 9, all stack trace locations report as line 71 of StackLocatorUtil. This is due to a bug in the JDK 9 implementation of StackLocator. The bug is that instead of dropping the top frames of the stack until the first frame that matches the fully-qualified class name of the logger, the implementation would drop all frames from the top that match the fully-qualified class name of the logger. Of course, at this point in the stack trace, there would be none. The fix is to reverse the condition, that we drop all frames until we reach a frame matching the fully-qualified class name of the logger, and then drop all frames matching the fully-qualified class name of the logger. This commit also adds a test that was broken before this change and now passes.