eclipse-ee4j / grizzly

Grizzly
https://eclipse-ee4j.github.io/grizzly
Other
147 stars 69 forks source link

ByteChunk.hashCode throws NPE #2128

Closed bseiller closed 1 year ago

bseiller commented 3 years ago

ByteChunk.hashCode https://github.com/eclipse-ee4j/grizzly/blob/a2ce7775658e11fbccbb9acd32e2daf2b0799f45/modules/http/src/main/java/org/glassfish/grizzly/http/util/ByteChunk.java#L642 misses null-checks for 3 of its members:

which results in a NPE when calling the method and those members are not initialized.

Steps to Reproduce:

See here https://github.com/bseiller/grizzly_http_bytechunk/blob/main/src/test/java/ByteChunkHashCodeTest.java for a unit-test that provokes the different NullPointerExceptions.

Possible Solution:

The easy fix would be to add checks/guards as found in ByteChunk.equals, An alternative would be to remove those members from the hashCode altogether - also see here: https://github.com/apache/tomcat/blob/main/java/org/apache/tomcat/util/buf/ByteChunk https://github.com/apache/tomcat/blob/main/java/org/apache/tomcat/util/buf/AbstractChunk.java