[jboss-jira] [JBoss JIRA] (LOGMGR-266) log4j2-jboss-logmanager LevelTranslator NullPointer

Boris Unckel (Jira) issues at jboss.org
Tue Mar 17 08:40:30 EDT 2020


    [ https://issues.redhat.com/browse/LOGMGR-266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14000799#comment-14000799 ] 

Boris Unckel edited comment on LOGMGR-266 at 3/17/20 8:40 AM:
--------------------------------------------------------------

There might be a second point:
org.jboss.logmanager.log4j.JBossLogger

{code:java}
    @Override
    public Level getLevel() {
    	final java.util.logging.Level julLevel = logger.getLevel();
    	// Fallback to EffectiveLevel if underlying java.util.logging.Logger's level is null 
    	int julLevelEffectiveInt;
    	if(julLevel == null) {
    		julLevelEffectiveInt = logger.getEffectiveLevel();
    	} else {
    		julLevelEffectiveInt = julLevel.intValue();
    	}
        return levelTranslator.translateLevel(julLevelEffectiveInt);
    }
{code}
and the translation by int in org.jboss.logmanager.log4j.LevelTranslator
{code:java}
    Level translateLevel(final int julLevelInt) {
    	final Level result = julToLog4j.get(julLevelInt);
        return result == null ? Level.INFO : result;
    }
{code}


was (Author: a13397):
There might be a second point:
org.jboss.logmanager.log4j.JBossLogger
{source}
    @Override
    public Level getLevel() {
    	final java.util.logging.Level julLevel = logger.getLevel();
    	// Fallback to EffectiveLevel if underlying java.util.logging.Logger's level is null 
    	int julLevelEffectiveInt;
    	if(julLevel == null) {
    		julLevelEffectiveInt = logger.getEffectiveLevel();
    	} else {
    		julLevelEffectiveInt = julLevel.intValue();
    	}
        return levelTranslator.translateLevel(julLevelEffectiveInt);
    }
{source}
and the translation by int in org.jboss.logmanager.log4j.LevelTranslator
{source}
    Level translateLevel(final int julLevelInt) {
    	final Level result = julToLog4j.get(julLevelInt);
        return result == null ? Level.INFO : result;
    }
{source}

> log4j2-jboss-logmanager LevelTranslator NullPointer
> ---------------------------------------------------
>
>                 Key: LOGMGR-266
>                 URL: https://issues.redhat.com/browse/LOGMGR-266
>             Project: JBoss Log Manager
>          Issue Type: Bug
>            Reporter: Boris Unckel
>            Priority: Critical
>
> We found the following Nullpointer Exception
> {code}
> Caused by: java.lang.NullPointerException
> 	at org.jboss.logmanager.log4j.LevelTranslator.translateLevel(LevelTranslator.java:95)
> 	at org.jboss.logmanager.log4j.JBossLogger.getLevel(JBossLogger.java:156)
> {code}
> ....
> Reason seems that LevelTranslator is not defensive enough. Suggestion:
> {code}
>     java.util.logging.Level translateLevel(final Level level) {
>         //level null is same as level not translated
>     	if(level == null) {
>         	return org.jboss.logmanager.Level.INFO;
>         }
>     	final java.util.logging.Level result = log4jToJul.get(level.intLevel());
>         return result == null ? org.jboss.logmanager.Level.INFO : result;
>     }
>     Level translateLevel(final java.util.logging.Level level) {
>      //level null is same as level not translated        
>         if(level == null) {
>         	return Level.INFO;
>         }
>     	final Level result = julToLog4j.get(level.intValue());
>         return result == null ? Level.INFO : result;
>     }
> {code}



--
This message was sent by Atlassian Jira
(v7.13.8#713008)


More information about the jboss-jira mailing list