Guarding ExtensionStack.toString() from NPE

This commit is contained in:
Joakim Erdfelt 2013-04-16 06:49:33 -07:00 committed by Jesse McConnell
parent 0b20467c6f
commit 119a1bb1cf
2 changed files with 35 additions and 11 deletions

View File

@ -251,19 +251,35 @@ public class ExtensionStack extends ContainerLifeCycle implements IncomingFrames
{
StringBuilder s = new StringBuilder();
s.append("ExtensionStack[");
s.append("extensions=[");
boolean delim = false;
for (Extension ext : extensions)
s.append("extensions=");
if (extensions == null)
{
if (delim)
{
s.append(',');
}
s.append(ext.getName());
delim = true;
s.append("<null>");
}
s.append("],incoming=").append(this.nextIncoming.getClass().getName());
s.append(",outgoing=").append(this.nextOutgoing.getClass().getName());
else
{
s.append('[');
boolean delim = false;
for (Extension ext : extensions)
{
if (delim)
{
s.append(',');
}
if (ext == null)
{
s.append("<null>");
}
else
{
s.append(ext.getName());
}
delim = true;
}
s.append(']');
}
s.append(",incoming=").append((this.nextIncoming == null)?"<null>":this.nextIncoming.getClass().getName());
s.append(",outgoing=").append((this.nextOutgoing == null)?"<null>":this.nextOutgoing.getClass().getName());
s.append("]");
return s.toString();
}

View File

@ -160,4 +160,12 @@ public class ExtensionStackTest
stack.stop();
}
}
@Test
public void testToString()
{
ExtensionStack stack = createExtensionStack();
// Shouldn't cause a NPE.
LOG.debug("Shouldn't cause a NPE: {}",stack.toString());
}
}