Return-Path: X-Original-To: apmail-logging-log4j-dev-archive@www.apache.org Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E181A11435 for ; Wed, 3 Sep 2014 05:48:53 +0000 (UTC) Received: (qmail 99026 invoked by uid 500); 3 Sep 2014 05:48:53 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 98922 invoked by uid 500); 3 Sep 2014 05:48:53 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 98826 invoked by uid 99); 3 Sep 2014 05:48:52 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Sep 2014 05:48:52 +0000 Date: Wed, 3 Sep 2014 05:48:52 +0000 (UTC) From: "Yogesh Rao (JIRA)" To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (LOG4J2-811) SimpleLogger throws ArrayIndexOutOfBoundsException for an empty array MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LOG4J2-811?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14119396#comment-14119396 ] Yogesh Rao edited comment on LOG4J2-811 at 9/3/14 5:48 AM: ----------------------------------------------------------- Also consider the case where the logging is done pretty much dynamic.. so one wouldnt be sure if the message generated to log has a placeholder within it. {code} for(...;...;...) { Sting s = // dynamically constructed string ... Here the user may or may not include the place holder Object[] param = // dynamically constructed param array logger.info(s,arr); } {code} Fixing the check for param array size > 0 should enable the user to use it such scenarios as well. WDYT ? was (Author: yogu13): Also consider the case where the logging is done pretty much dynamic.. so one wouldnt be sure if the message generated to log has a placeholder within it. for(...;...;...) { Sting s = // dynamically constructed string ... Here the user may or may not include the place holder Object[] param = // dynmically constructed param array logger.info(s,arr); } Fixing the check for param array size > 0 should enable the user to use it such scenarios as well. WDYT ? > SimpleLogger throws ArrayIndexOutOfBoundsException for an empty array > --------------------------------------------------------------------- > > Key: LOG4J2-811 > URL: https://issues.apache.org/jira/browse/LOG4J2-811 > Project: Log4j 2 > Issue Type: Bug > Components: API > Affects Versions: 2.0.1 > Reporter: Yogesh Rao > Labels: patch > Fix For: 2.1 > > > There seems to be an issue with SimpleLogger implementation provided by log4j2. The issue seems to be in the new improved API supporting placeholders and var args when called with an Object Array of size 0. > for e.g logger.error("Hello World {} in {} " , new Object[0]); > A statement above results in an error as shown below > ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger > Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 > at org.apache.logging.log4j.simple.SimpleLogger.logMessage(SimpleLogger.java:157) > at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1347) > at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1312) > at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:539) > at TestError.main(TestError.java:21) > Solution to place a check in SimpleLogger for checking the size of the array . -- 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