logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rogério Lecarião Leite (JIRA) <j...@apache.org>
Subject [jira] [Comment Edited] (LOG4J2-1542) java.lang.ArrayIndexOutOfBoundsException
Date Tue, 23 Aug 2016 22:46:20 GMT

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

Rogério Lecarião Leite edited comment on LOG4J2-1542 at 8/23/16 10:45 PM:
--------------------------------------------------------------------------

Hi Gary,

{code:borderStyle=solid}
run:
2016/08/23 19:30:57.683 TRACE [@Application-Client][THREAD(main)](Utils.java:46)
                              [m]a[/m]
2016-08-23 19:30:57,686 AsyncAppender-AsyncFile ERROR An exception occurred processing Appender
FileLog java.lang.ArrayIndexOutOfBoundsException: 0
	at org.apache.logging.log4j.message.ParameterizedMessage.formatTo(ParameterizedMessage.java:221)
	at org.apache.logging.log4j.core.pattern.MessagePatternConverter.format(MessagePatternConverter.java:65)
	at org.apache.logging.log4j.core.pattern.PatternFormatter.formatWithInfo(PatternFormatter.java:45)
	at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:40)
	at org.apache.logging.log4j.core.layout.PatternLayout$PatternSerializer.toSerializable(PatternLayout.java:294)
	at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:195)
	at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:180)
	at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:57)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:120)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:113)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:104)
	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:155)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:128)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:119)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
	at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.callAppenders(AsyncAppender.java:338)
	at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.run(AsyncAppender.java:291)

BUILD SUCCESSFUL (total time: 5 seconds)
{code}

{code:xml|borderStyle=solid}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="ProjectApplicationClient" status="WARN" monitorInterval="2000">
    <Properties>
        <Property name="fileoutname">log_$${date:yyyy-MM-dd_HH-mm-ss}.txt</Property>
        <Property name="fileoutpath">file://${fileoutname}</Property>
        <Property name="patternlayout">%d{yyyy/MM/dd HH:mm:ss.SSS} %-5p [@Application-Client][CLASS(%-1.64c{10})][THREAD(%-1.32t)](%F:%L)%n
                             [m]%-1.2048m[/m]%n</Property>

	</Properties>
    <Appenders>
        <Console name="ConsoleOut" target="SYSTEM_OUT">
            <Filters>
                <ThresholdFilter level="TRACE" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout pattern="${patternlayout}"/>
        </Console>
        <Console name="ConsoleErr" target="SYSTEM_ERR">
            <Filters>
                <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout>
                <Pattern>${patternlayout}</Pattern>
            </PatternLayout>
        </Console>
        <File name="FileLog"
              fileName="${fileoutname}"
              bufferSize="0"
              bufferedIO="false"
              advertiseURI="${fileoutpath}"
              advertise="true"
              append="false">
            <PatternLayout pattern="${patternlayout}"/>
        </File>
        <Async name="AsyncFile">
            <AppenderRef ref="FileLog"/>
        </Async>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="AsyncFile"/>
            <AppenderRef ref="ConsoleOut"/>
            <AppenderRef ref="ConsoleErr"/>
        </Root>
    </Loggers>
</Configuration>
{code}

See the comments ;D
{code:title=ParameterizedMessage.java|borderStyle=solid}
@Override
    public void formatTo(final StringBuilder buffer) {
        if (formattedMessage != null) {
            buffer.append(formattedMessage);
        } else {
            if (indices[0] < 0) {/*LOG4J2-1542: this point indices.length is equals to
zero. Check array length first? */
                ParameterFormatter.formatMessage(buffer, messagePattern, argArray, usedCount);
            } else {
                ParameterFormatter.formatMessage2(buffer, messagePattern, argArray, usedCount,
indices);
            }
        }
    }
{code}



was (Author: rogeriolleite):
Hi Gary,

{code}
run:
2016/08/23 19:30:57.683 TRACE [@Application-Client][THREAD(main)](Utils.java:46)
                              [m]a[/m]
2016-08-23 19:30:57,686 AsyncAppender-AsyncFile ERROR An exception occurred processing Appender
FileLog java.lang.ArrayIndexOutOfBoundsException: 0
	at org.apache.logging.log4j.message.ParameterizedMessage.formatTo(ParameterizedMessage.java:221)
	at org.apache.logging.log4j.core.pattern.MessagePatternConverter.format(MessagePatternConverter.java:65)
	at org.apache.logging.log4j.core.pattern.PatternFormatter.formatWithInfo(PatternFormatter.java:45)
	at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:40)
	at org.apache.logging.log4j.core.layout.PatternLayout$PatternSerializer.toSerializable(PatternLayout.java:294)
	at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:195)
	at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:180)
	at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:57)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:120)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:113)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:104)
	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:155)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:128)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:119)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
	at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.callAppenders(AsyncAppender.java:338)
	at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.run(AsyncAppender.java:291)

BUILD SUCCESSFUL (total time: 5 seconds)
{code}

{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="ProjectApplicationClient" status="WARN" monitorInterval="2000">
    <Properties>
        <Property name="fileoutname">log_$${date:yyyy-MM-dd_HH-mm-ss}.txt</Property>
        <Property name="fileoutpath">file://${fileoutname}</Property>
        <Property name="patternlayout">%d{yyyy/MM/dd HH:mm:ss.SSS} %-5p [@Application-Client][CLASS(%-1.64c{10})][THREAD(%-1.32t)](%F:%L)%n
                             [m]%-1.2048m[/m]%n</Property>

	</Properties>
    <Appenders>
        <Console name="ConsoleOut" target="SYSTEM_OUT">
            <Filters>
                <ThresholdFilter level="TRACE" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout pattern="${patternlayout}"/>
        </Console>
        <Console name="ConsoleErr" target="SYSTEM_ERR">
            <Filters>
                <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout>
                <Pattern>${patternlayout}</Pattern>
            </PatternLayout>
        </Console>
        <File name="FileLog"
              fileName="${fileoutname}"
              bufferSize="0"
              bufferedIO="false"
              advertiseURI="${fileoutpath}"
              advertise="true"
              append="false">
            <PatternLayout pattern="${patternlayout}"/>
        </File>
        <Async name="AsyncFile">
            <AppenderRef ref="FileLog"/>
        </Async>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="AsyncFile"/>
            <AppenderRef ref="ConsoleOut"/>
            <AppenderRef ref="ConsoleErr"/>
        </Root>
    </Loggers>
</Configuration>
{code}


> java.lang.ArrayIndexOutOfBoundsException
> ----------------------------------------
>
>                 Key: LOG4J2-1542
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1542
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.6.2
>         Environment: Array length logic causes throw java.lang.ArrayIndexOutOfBoundsException
>            Reporter: Rogério Lecarião Leite
>            Priority: Critical
>              Labels: easyfix
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> This error is reproducible when method fomarTo of the class ParameterizedMessage is invoked.
> This root cause is the method init of same class where is invoked, in the this.indices
is initializaded with messagePattern.length() >> 1 run to equals zero because that messagePattern.length()
is 1 (string with one character).
> I used File Appender in my XML config and I wrote my code with logger.trace("a").
> My PatternLayout used is pattern="%m" (simplest).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message