Return-Path: X-Original-To: apmail-logging-log4j-user-archive@www.apache.org Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6DA1111488 for ; Tue, 2 Sep 2014 16:15:57 +0000 (UTC) Received: (qmail 87409 invoked by uid 500); 2 Sep 2014 16:15:57 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 87353 invoked by uid 500); 2 Sep 2014 16:15:57 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 87342 invoked by uid 99); 2 Sep 2014 16:15:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Sep 2014 16:15:57 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ralph.goers@dslextreme.com designates 209.85.220.44 as permitted sender) Received: from [209.85.220.44] (HELO mail-pa0-f44.google.com) (209.85.220.44) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Sep 2014 16:15:29 +0000 Received: by mail-pa0-f44.google.com with SMTP id rd3so14986030pab.17 for ; Tue, 02 Sep 2014 09:15:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:content-transfer-encoding:message-id:references:to; bh=bg70HXjJEhcyoBGoG3CaPDQeJKnE9usJdTXk7YCyYQ0=; b=BpkdkrQfcjBM6aP6mWh1luOtNGrn/2PUepP+wMSC2IW+phSwN9sNaIsWjjhz2xk5hJ 4bwVDqBzV3Yy4QEWb8d/95FqqfQNfAeLEES/voyrZfKOI5Oez7tMyN6B+VeSkLsxuP9B fMwRj7+Sd+ufGpkgTvybvJybkxHZqbd7SVmhxGxrypgaQy4EcP96MOS/bSnoEd16nqY4 Nc2k+sP7WCTOV70eilpCAT/QNIr8vTp+HZQX9RoxdBAO5eSXHZSHPXYxU8sQQBWpZ3tQ vV/tYbU52bE/MD/lrzZxdKAAlMCPCA4e+YfFE5Q3pFOsN9Eicu0flDYQC3FXueDkugg/ xK0g== X-Gm-Message-State: ALoCoQmRL+bFP+Rksvq4Xfc68eFftsYXK/hGZ5HLB5q3o97QogQn66cvsUxgYXCMiH/oHU3Pvrmw X-Received: by 10.68.200.101 with SMTP id jr5mr48982317pbc.36.1409674527667; Tue, 02 Sep 2014 09:15:27 -0700 (PDT) Received: from [10.0.45.224] ([208.93.128.118]) by mx.google.com with ESMTPSA id t14sm4467997pbs.12.2014.09.02.09.15.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 09:15:27 -0700 (PDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: Log4j2's SimpleLogger Implementation Issue for var args method's From: Ralph Goers In-Reply-To: Date: Tue, 2 Sep 2014 09:15:22 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <426E94D0-8FB5-4E42-A1ED-BACC2FA008D3@dslextreme.com> References: To: Log4J Users List X-Mailer: Apple Mail (2.1878.6) X-Virus-Checked: Checked by ClamAV on apache.org What will you do instead of throwing an ArrayIndexOutOfBoundsException? = This is obviously a user error. It would be misleading (but maybe = acceptable) to substitute =93null=94 for the placeholders, but just = throwing a different exception probably isn=92t worth the trouble. Ralph On Sep 2, 2014, at 7:24 AM, Yogesh Rao wrote: > Hi, >=20 > 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. >=20 > for e.g logger.error("Hello World {} in {} " , new Object[0]); >=20 > A statement above results in an error as shown below >=20 > 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.ja= va:1312) > at > = org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:539)= > at TestError.main(TestError.java:21) >=20 >=20 >=20 > I managed to look at the code as well and it looks like a condition to > check of the var arg param array size is missing in SimpleLogger >=20 > 155 final Object[] params =3D msg.getParameters(); > 156 Throwable t; > 157 if (throwable =3D=3D null && params !=3D null && > params[params.length - 1] instanceof Throwable) { > 158 t =3D (Throwable) params[params.length - 1]; > 159 } else { > 160 t =3D throwable; > 161 } > 162 if (t !=3D null) { > 163 sb.append(SPACE); > 164 final ByteArrayOutputStream baos =3D new > ByteArrayOutputStream(); > 165 t.printStackTrace(new PrintStream(baos)); > 166 sb.append(baos.toString()); > 167 } > 168 stream.println(sb.toString()); >=20 >=20 > I can raise a JIRA issue and provide a fix with failing unit testcase. = Let > me know if i can proceed ahead on this. >=20 > Details of the environment are :- > Version used >=20 > 1. JDK - Oracle JDK version 1.7 > 2. Log4j2 API - 2.0.1 >=20 >=20 > To reproduce following java class can be used : >=20 > TestError.java > ------------------------ >=20 > import org.apache.logging.log4j.LogManager; > import org.apache.logging.log4j.Logger; >=20 >=20 >=20 > public class TestError { >=20 > private static final Logger logger =3D = LogManager.getLogger("TestError"); > /** > * @param args > */ > public static void main(String[] args) { > Object[] arr =3D null; > logger.error("Hello World {} in {} " , new Object[0]); >=20 > } >=20 > } >=20 > Jars in Classpath > -------------------------- > Log4j2 API - 2.0.1 >=20 >=20 > Regards, > -Yogesh --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.apache.org