Fixed bug in AbstractFrameBytes.compareTo(), avoiding NPE when comparing

FrameBytes that have a related stream, and those that don't (such as PING).
This commit is contained in:
Simone Bordet 2012-06-03 22:53:06 +02:00
parent a2a9fd59a2
commit c9251e5c73
1 changed files with 13 additions and 5 deletions

View File

@ -770,10 +770,10 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
synchronized (this) synchronized (this)
{ {
ByteBuffer buffer = generator.control(frame); ByteBuffer buffer = generator.control(frame);
logger.debug("Queuing {} on {}",frame,stream); logger.debug("Queuing {} on {}", frame, stream);
ControlFrameBytes<C> frameBytes = new ControlFrameBytes<>(stream,handler,context,frame,buffer); ControlFrameBytes<C> frameBytes = new ControlFrameBytes<>(stream, handler, context, frame, buffer);
if (timeout > 0) if (timeout > 0)
frameBytes.task = scheduler.schedule(frameBytes,timeout,unit); frameBytes.task = scheduler.schedule(frameBytes, timeout, unit);
// Special handling for PING frames, they must be sent as soon as possible // Special handling for PING frames, they must be sent as soon as possible
if (ControlFrameType.PING == frame.getType()) if (ControlFrameType.PING == frame.getType())
@ -1061,8 +1061,16 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
@Override @Override
public int compareTo(FrameBytes that) public int compareTo(FrameBytes that)
{ {
// If this.stream.priority > that.stream.priority => -1 (this.stream has less priority than that.stream) // FrameBytes may have or not have a related stream (for example, PING do not have a related stream)
return that.getStream().getPriority() - getStream().getPriority(); // FrameBytes without related streams have higher priority
IStream thisStream = getStream();
IStream thatStream = that.getStream();
if (thisStream == null)
return thatStream == null ? 0 : -1;
if (thatStream == null)
return 1;
// If this.stream.priority > that.stream.priority => this.stream has less priority than that.stream
return thatStream.getPriority() - thisStream.getPriority();
} }
@Override @Override