306783 NPE for throwable

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1403 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-03-23 16:36:56 +00:00
parent 798c664698
commit da9f167b31
3 changed files with 92 additions and 21 deletions

View File

@ -1,3 +1,6 @@
jetty-7.0.2.SNAPSHOT
+ 306783 - NPE in StdErrLog when Throwable is null
jetty-7.0.2.RC0
+ JSON parses NaN as null
+ 290765 Reset input for HttpExchange retry.

View File

@ -226,18 +226,18 @@ public class StdErrLog implements Logger
private void format(String msg, Object arg0, Object arg1)
{
int i0=msg.indexOf("{}");
int i0=msg==null?-1:msg.indexOf("{}");
int i1=i0<0?-1:msg.indexOf("{}",i0+2);
if (i0>=0)
{
format(msg.substring(0,i0));
format(String.valueOf(arg0));
format(String.valueOf(arg0==null?"null":arg0));
if (i1>=0)
{
format(msg.substring(i0+2,i1));
format(String.valueOf(arg1));
format(String.valueOf(arg1==null?"null":arg1));
format(msg.substring(i1+2));
}
else
@ -268,32 +268,40 @@ public class StdErrLog implements Logger
private void format(String msg)
{
for (int i=0;i<msg.length();i++)
{
char c=msg.charAt(i);
if (Character.isISOControl(c))
if (msg == null)
_buffer.append("null");
else
for (int i=0;i<msg.length();i++)
{
if (c=='\n')
_buffer.append('|');
else if (c=='\r')
_buffer.append('<');
char c=msg.charAt(i);
if (Character.isISOControl(c))
{
if (c=='\n')
_buffer.append('|');
else if (c=='\r')
_buffer.append('<');
else
_buffer.append('?');
}
else
_buffer.append('?');
_buffer.append(c);
}
else
_buffer.append(c);
}
}
private void format(Throwable th)
{
_buffer.append(LN);
format(th.toString());
StackTraceElement[] elements = th.getStackTrace();
for (int i=0;elements!=null && i<elements.length;i++)
if (th == null)
_buffer.append("null");
else
{
_buffer.append(LN).append("\tat ");
format(elements[i].toString());
_buffer.append('\n');
format(th.toString());
StackTraceElement[] elements = th.getStackTrace();
for (int i=0;elements!=null && i<elements.length;i++)
{
_buffer.append("\n\tat ");
format(elements[i].toString());
}
}
}

View File

@ -0,0 +1,60 @@
// ========================================================================
// Copyright (c) 2010-2010 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.log;
import junit.framework.TestCase;
/**
* @author mgorovoy
* */
public class StdErrLogTest extends TestCase
{
public void testNullValues()
{
StdErrLog log = new StdErrLog();
log.setDebugEnabled(true);
try {
log.info("Testing info(msg,null,null) - {} {}",null,null);
log.info("Testing info(msg,null,null) - {}",null,null);
log.info("Testing info(msg,null,null)",null,null);
log.info(null,"- Testing","info(null,arg0,arg1)");
log.info(null,null,null);
log.debug("Testing debug(msg,null,null) - {} {}",null,null);
log.debug("Testing debug(msg,null,null) - {}",null,null);
log.debug("Testing debug(msg,null,null)",null,null);
log.debug(null,"- Testing","debug(null,arg0,arg1)");
log.debug(null,null,null);
log.debug("Testing debug(msg,null)",null);
log.debug(null,new Throwable("IGNORE::Testing debug(null,thrw)").fillInStackTrace());
log.warn("Testing warn(msg,null,null) - {} {}",null,null);
log.warn("Testing warn(msg,null,null) - {}",null,null);
log.warn("Testing warn(msg,null,null)",null,null);
log.warn(null,"- Testing","warn(msg,arg0,arg1)");
log.warn(null,null,null);
log.warn("Testing warn(msg,null)",null);
log.warn(null,new Throwable("IGNORE::Testing warn(msg,thrw)").fillInStackTrace());
}
catch (NullPointerException npe)
{
assertTrue("NullPointerException in StdErrLog.", false);
System.err.println(npe);
npe.printStackTrace();
}
}
}