479179 Fixed NPE from debug

This commit is contained in:
Greg Wilkins 2015-10-17 09:37:43 +11:00
parent 27a41a4f77
commit 570c751ec8
2 changed files with 40 additions and 34 deletions

View File

@ -212,7 +212,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
public void onFillable() public void onFillable()
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("{} onFillable enter {}", this, _channel.getState()); LOG.debug("{} onFillable enter {} {}", this, _channel.getState(),BufferUtil.toDetailString(_requestBuffer));
HttpConnection last=setCurrentConnection(this); HttpConnection last=setCurrentConnection(this);
try try
@ -259,7 +259,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{ {
setCurrentConnection(last); setCurrentConnection(last);
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("{} onFillable exit {}", this, _channel.getState()); LOG.debug("{} onFillable exit {} {}", this, _channel.getState(),BufferUtil.toDetailString(_requestBuffer));
} }
} }
@ -272,8 +272,6 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
boolean handled=false; boolean handled=false;
while (_parser.inContentState()) while (_parser.inContentState())
{ {
if (LOG.isDebugEnabled())
LOG.debug("{} parseContent",this);
int filled = fillRequestBuffer(); int filled = fillRequestBuffer();
boolean handle = parseRequestBuffer(); boolean handle = parseRequestBuffer();
handled|=handle; handled|=handle;
@ -300,7 +298,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
// No pretend we read -1 // No pretend we read -1
_parser.atEOF(); _parser.atEOF();
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("{} filled -1",this); LOG.debug("{} filled -1 {}",this,BufferUtil.toDetailString(_requestBuffer));
return -1; return -1;
} }
@ -321,7 +319,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
_parser.atEOF(); _parser.atEOF();
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("{} filled {}",this,filled); LOG.debug("{} filled {} {}",this,filled,BufferUtil.toDetailString(_requestBuffer));
return filled; return filled;
} }
@ -559,8 +557,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
super.toString(), super.toString(),
_parser, _parser,
_generator, _generator,
_channel, _channel);
BufferUtil.toDetailString(_requestBuffer));
} }
private class Content extends HttpInput.Content private class Content extends HttpInput.Content

View File

@ -32,6 +32,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
@ -1027,38 +1028,46 @@ public class BufferUtil
private static void appendDebugString(StringBuilder buf,ByteBuffer buffer) private static void appendDebugString(StringBuilder buf,ByteBuffer buffer)
{ {
for (int i = 0; i < buffer.position(); i++) try
{ {
appendContentChar(buf,buffer.get(i)); for (int i = 0; i < buffer.position(); i++)
if (i == 16 && buffer.position() > 32)
{ {
buf.append("..."); appendContentChar(buf,buffer.get(i));
i = buffer.position() - 16; if (i == 16 && buffer.position() > 32)
{
buf.append("...");
i = buffer.position() - 16;
}
} }
buf.append("<<<");
for (int i = buffer.position(); i < buffer.limit(); i++)
{
appendContentChar(buf,buffer.get(i));
if (i == buffer.position() + 16 && buffer.limit() > buffer.position() + 32)
{
buf.append("...");
i = buffer.limit() - 16;
}
}
buf.append(">>>");
int limit = buffer.limit();
buffer.limit(buffer.capacity());
for (int i = limit; i < buffer.capacity(); i++)
{
appendContentChar(buf,buffer.get(i));
if (i == limit + 16 && buffer.capacity() > limit + 32)
{
buf.append("...");
i = buffer.capacity() - 16;
}
}
buffer.limit(limit);
} }
buf.append("<<<"); catch(Throwable x)
for (int i = buffer.position(); i < buffer.limit(); i++)
{ {
appendContentChar(buf,buffer.get(i)); Log.getRootLogger().ignore(x);
if (i == buffer.position() + 16 && buffer.limit() > buffer.position() + 32) buf.append("!!concurrent mod!!");
{
buf.append("...");
i = buffer.limit() - 16;
}
} }
buf.append(">>>");
int limit = buffer.limit();
buffer.limit(buffer.capacity());
for (int i = limit; i < buffer.capacity(); i++)
{
appendContentChar(buf,buffer.get(i));
if (i == limit + 16 && buffer.capacity() > limit + 32)
{
buf.append("...");
i = buffer.capacity() - 16;
}
}
buffer.limit(limit);
} }
private static void appendContentChar(StringBuilder buf, byte b) private static void appendContentChar(StringBuilder buf, byte b)