Fix possible NPE in DefaultHttp2UnknownFrame#equals (#9625)

Motivation:
`DefaultHttp2UnknownFrame#equals` may produce NPE due to
incorrect comparison of `stream` field.

Modification:
- Fix the `stream` field compare.
- Cleanup usage of class fields: use direct access instead of getters
(because the class is final).

Result:
No NPE in `equals` method.
This commit is contained in:
Nikolay Fedorovskikh 2019-10-07 12:00:38 +05:00 committed by Norman Maurer
parent 47040bd791
commit 873761f9bd

View File

@ -80,7 +80,7 @@ public final class DefaultHttp2UnknownFrame extends DefaultByteBufHolder impleme
@Override @Override
public DefaultHttp2UnknownFrame replace(ByteBuf content) { public DefaultHttp2UnknownFrame replace(ByteBuf content) {
return new DefaultHttp2UnknownFrame(frameType, flags, content).stream(stream()); return new DefaultHttp2UnknownFrame(frameType, flags, content).stream(stream);
} }
@Override @Override
@ -97,8 +97,8 @@ public final class DefaultHttp2UnknownFrame extends DefaultByteBufHolder impleme
@Override @Override
public String toString() { public String toString() {
return StringUtil.simpleClassName(this) + "(frameType=" + frameType() + ", stream=" + stream() + return StringUtil.simpleClassName(this) + "(frameType=" + frameType + ", stream=" + stream +
", flags=" + flags() + ", content=" + contentToString() + ')'; ", flags=" + flags + ", content=" + contentToString() + ')';
} }
@Override @Override
@ -119,18 +119,20 @@ public final class DefaultHttp2UnknownFrame extends DefaultByteBufHolder impleme
return false; return false;
} }
DefaultHttp2UnknownFrame other = (DefaultHttp2UnknownFrame) o; DefaultHttp2UnknownFrame other = (DefaultHttp2UnknownFrame) o;
return super.equals(other) && flags().equals(other.flags()) Http2FrameStream otherStream = other.stream();
&& frameType() == other.frameType() && (stream() == null && other.stream() == null) || return (stream == otherStream || otherStream != null && otherStream.equals(stream))
stream().equals(other.stream()); && flags.equals(other.flags())
&& frameType == other.frameType()
&& super.equals(other);
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = super.hashCode(); int hash = super.hashCode();
hash = hash * 31 + frameType(); hash = hash * 31 + frameType;
hash = hash * 31 + flags().hashCode(); hash = hash * 31 + flags.hashCode();
if (stream() != null) { if (stream != null) {
hash = hash * 31 + stream().hashCode(); hash = hash * 31 + stream.hashCode();
} }
return hash; return hash;