You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2022/09/13 04:05:00 UTC

[jira] [Commented] (LOG4J2-3593) StackLocator Reflection.getCallerClass warning is misleading / incorrect

    [ https://issues.apache.org/jira/browse/LOG4J2-3593?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17603326#comment-17603326 ] 

Ralph Goers commented on LOG4J2-3593:
-------------------------------------

I am afraid I don't understand. Log4j has 2 versions of the StackLocator class; one for Java 8 and one for Java 9+. The Java 9 version exists under the META-INF/versions/9 in accordance with how multi-release jars work. If you are running in Java 8 the Java 8 version will be used and this error will not appear. If you are running in Java 9 and multi-release jars are not supported you will also end up using the Java 8 version and StackLocator will determine that it cannot use sun.reflect.Reflection because it is not present. That will cause the warning message and StackLocator will fail to find the caller's class. Walking the stack trace isn't really an option because that simply returns the class name whereas the code requires the actual class object.

But you are correct that the message is misleading.

> StackLocator Reflection.getCallerClass warning is misleading / incorrect
> ------------------------------------------------------------------------
>
>                 Key: LOG4J2-3593
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3593
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.17.2
>            Reporter: Marcono1234
>            Priority: Major
>
> When the pre-Java 9 {{StackLocator}} is used, but {{Reflection.getCallerClass}} is missing, the following warning is printed to console:
> {quote}
> WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
> {quote}
> This can for example occur when a JAR with dependencies is created but the Log4j Java 9 specific code is not included, or {{Multi-Release: true}} is not set in the manifest (see also LOG4J2-2834).
> The issue is that the warning is misleading or incorrect. It suggests that Log4j is still fully functional, but as seen with LOG4J2-2834, certain functionality breaks (such as {{LogManager.getLogger()}}). 
> So maybe the underlying issue here is that the warning is correct, but there is a bug in {{StackLocator}} and it should actually fall back to using {{new Throwable().getStackTrace()}} instead of returning {{null}}?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)