logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Williams <nicho...@nicholaswilliams.net>
Subject We have to stop using Reflection#getCallerClass(int)
Date Wed, 26 Jun 2013 00:04:46 GMT
As some of you may know, sun.reflect.Reflection#getCallerClass(int) was removed in Java 8 (it
was replaced with no-arg Reflection#getCallerClass(), which uses non-public @CallerSensitive).
This resulted in LOG4J2-245 [1] (EmptyStackException on Java 8), which was resolved with using
a backup option (SecurityManager#getClassContext()) in the hopes that a replacement would
be found. I have been actively involved in discussions on the Java 8 Core Libraries mailing
list to replace this behavior with a public API in Java 8 [2,3].

It has now come to my attention that the changes to Reflection#getCallerClass(...) have been
back-ported to Java 7 now [4,5] (effective 1.7.0_25, released in the last week or so). Since
it's a non-public API, they're free to do this any time they want, but it will cause a nightmare
for Log4j users using 1.7.0_25 and higher. Here are the exact changes that were made:

1) Added no-arg Reflection#getCallerClass() that uses back-ported @CollerSensitive.
2) Left Reflection#getCallerClass(int) in place, but it now THROWS an UnsupportedOperationException
(which is even worse ... the fix for LOG4J2-245 won't pick this up and make it work for 1.7.0_25+
3) In Java 7 _only_ (won't work for Java 8) users can specify jdk.reflect.allowGetCallerClass
system property to enable Reflection#getCallerClass(int). I submit this will not be an option
our users are willing to accept, but it is a temporary workaround.

Here's hoping they add a public API in Java 8 to make what we're using this for easier (I'm
pushing as hard as I can), but it looks like Java 7 is broke for good. We should probably
add in a check so that getCallerClass is not used unless Java major version is 6.

I do not know how this change will impact Log4j 1.x. Hopefully it won't.


[1] https://issues.apache.org/jira/browse/LOG4J2-245
[2] http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018049.html
[3] http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018353.html
[4] http://mail.openjdk.java.net/pipermail/jdk7u-dev/2013-June/006791.html
[5] http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018349.html
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message