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

@ -1061,8 +1061,16 @@ public class StandardSession implements ISession, Parser.Listener, Handler<Stand
@Override
public int compareTo(FrameBytes that)
{
// If this.stream.priority > that.stream.priority => -1 (this.stream has less priority than that.stream)
return that.getStream().getPriority() - getStream().getPriority();
// FrameBytes may have or not have a related stream (for example, PING do not have a related stream)
// 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